我想从此 Google 搜索中提取数据
https://www.google.com.ph/?gfe_rd=cr&ei=JQ7bVZjRDOSL8QeqibewAwgws_rd=ssl#q=scarlett+johansson+age
我想通过获取这个特定的 div 标签来获取艺术家的年龄
<div class="_eF">30 years (November 22, 1984)</div>
这是我到目前为止的代码
Document doc = Jsoup.connect("https://www.google.com.ph/?gfe_rd=cr&ei=eKfaVbWXBomM8QexmIOACw&gws_rd=ssl#q=scarlett+johansson+age").get();
Elements age = doc.getElementsByClass("#_eF");
String urlSource = age.html();
但我得到的只是 javascript 代码,而不是实际的 html 源代码
最佳答案
你做错了。通过执行 doc.getElementsByClass,您可以获得多个结果(或者 Jsoup 处理这些结果)。
你想做的是:
Document doc = Jsoup.connect("https://www.google.com.ph/?gfe_rd=cr&ei=eKfaVbWXBomM8QexmIOACw&gws_rd=ssl#q=scarlett+johansson+age").get();
Elements age = doc.select("div._eF");
String urlSource = age.html();
关于java - 从google搜索获取html源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32182653/