import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
public class YoutubeBot {
private static final String YOUTUBE = "http://www.youtube.com";
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
WebClient webClient = new WebClient();
webClient.setThrowExceptionOnScriptError(false);
// This is equivalent to typing youtube.com to the adress bar of browser
HtmlPage currentPage = webClient.getPage("http://www.youtube.com/results?search_type=videos&search_query=official+music+video&search_sort=video_date_uploaded&suggested_categories=10%2C24&uni=3");
// Get form where submit button is located
HtmlForm searchForm = (HtmlForm) currentPage.getElementById("masthead-search");
// Get the …Run Code Online (Sandbox Code Playgroud) 我有2个可能的div.
<div class='a b'></div>
Run Code Online (Sandbox Code Playgroud)
和
<div class='c d'></div>
Run Code Online (Sandbox Code Playgroud)
有没有办法检查div元素是否有2个类a和b?
我使用Ruby,Capybara和XPath来选择元素,但如果可以解决问题,则css很好.
有时我会在开头和结尾看到带有双下划线的变量名.例如:
Article.__elasticsearch__
Run Code Online (Sandbox Code Playgroud)
是否有一些与Ruby变量名称中的双下划线相关的命名约定?
我需要从JavaSpaces开始,我发现了这篇文章.但是我找到了JINI库并下载了它,但是找不到JavaSpaces库.是移动到JINI还是什么?
我正在尝试解析Youtube Gdata以查看是否存在具有给定ID的视频.但是没有正常的标签,但有命名空间.在链接http://gdata.youtube.com/feeds/api/videos?q=KgfdlZuVz7I上有标记:
<openSearch:totalResults>1</openSearch:totalResults>
Run Code Online (Sandbox Code Playgroud)
有命名空间openSearch:
xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在Nokogiri和Ruby中处理它.
这是代码的一部分:
xmlfeed = Nokogiri::HTML(open("http://gdata.youtube.com/feeds/api/videos?q=#{video_id}"))
xmlfeed.at_xpath("openSearch:totalResults")
Run Code Online (Sandbox Code Playgroud)
它给出了错误:
Undefined namespace prefix: openSearch:totalResults
Run Code Online (Sandbox Code Playgroud) 当我尝试安装rmagic时:
gem install rmagic
Run Code Online (Sandbox Code Playgroud)
它给出了错误:
Building native extensions. This could take a while...
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
/home/biske/.rbenv/versions/2.0.0-p247/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.4.9... yes
checking for HDRI disabled version of ImageMagick... yes
checking for stdint.h... yes
checking for sys/types.h... yes
checking for wand/MagickWand.h... no
Can't install RMagick 2.13.2. Can't find MagickWand.h.
*** extconf.rb failed ***
Could …Run Code Online (Sandbox Code Playgroud) 我读到Eclipse Indigo安装了Window Builder Pro插件,但我看不到它在哪里.File/New/Project不允许我选择Window Builder Pro.怎么找到它?
我必须编写n从用户获取数字的程序,然后计算总和:s = 1/1 + 1/2 + ... + 1/n.
我写了这段代码:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner unos = new Scanner(System.in);
System.out.println("n=?");
int n = unos.nextInt();
double s = 0.0;
for (int i = 1; i <= n; i++) {
s = s + (1.0 / i);
}
System.out.println("s=" + s);
}
}
Run Code Online (Sandbox Code Playgroud)
Java如何决定i在此语句中将int值转换为double:
s = s + (1.0 / i);
Run Code Online (Sandbox Code Playgroud) 有没有办法在Rails中自定义消息以确认字段?例如在设计中我必须输入密码和password_confirmation,错误信息是:
密码确认与密码不匹配
我可以更改活动记录区域设置消息("不匹配"),但它在该区域设置消息的开头和结尾输出密码确认和密码,所以我得到这样的信息:
"密码确认必须与密码匹配"
有没有办法将其更改为不同的字符串?
密码确认和密码必须匹配.
编辑
另一件事是拥有完全自定义的消息,例如:
"设置密码"和"确认密码"必须匹配.
我为模型写了测试:
describe Video do
describe 'searching youtube for video existence' do
it 'should return true if video exists' do
Video.video_exists?("http://www.youtube.com/watch?v=KgfdlZuVz7I").should be_true
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是型号代码:
class Video < ActiveRecord::Base
attr_accessible :video_id
def self.video_exists?(video_url)
video_url =~ /\?v=(.*?)&/
xmlfeed = Nokogiri::HTML(open("http://gdata.youtube.com/feeds/api/videos?q=#{$1}"))
if xmlfeed.at_xpath("//openSearch:totalResults").content.to_i == 0
return false
else
return true
end
end
end
Run Code Online (Sandbox Code Playgroud)
但它失败了,错误:
Failures:
1) Video searching youtube for video existence should return true if video exists
Failure/Error: Video.video_exists?("http://www.youtube.com/watch?v=KgfdlZuVz7I").should be_true
NameError:
uninitialized constant Video::Nokogiri
# ./app/models/video.rb:6:in `video_exists?'
# ./spec/models/video_spec.rb:6:in `block (3 …Run Code Online (Sandbox Code Playgroud)