Java 如何使用jsoup访问子类
我想访问此网页:并提取中线图中的数据。html文件是(在这里,我只粘贴我使用的部分): 打印“中心”类时,可以得到除“报表内容”之外的所有子类内容,打印“报表内容”时,结果只有:Java 如何使用jsoup访问子类,java,web-crawler,jsoup,Java,Web Crawler,Jsoup,我想访问此网页:并提取中线图中的数据。html文件是(在这里,我只粘贴我使用的部分): 打印“中心”类时,可以得到除“报表内容”之外的所有子类内容,打印“报表内容”时,结果只有: <div id="reportContent" Class="report-content"></div> 但仍然根本不起作用。我如何在这里获取脚本中的数据?我感谢你的帮助 尝试通过Id获取相同的标签,您将获得完整的标签请尝试以下url: https://www.google.co
<div id="reportContent" Class="report-content"></div>
但仍然根本不起作用。我如何在这里获取脚本中的数据?我感谢你的帮助 尝试通过Id获取相同的标签,您将获得完整的标签请尝试以下url:
https://www.google.com/trends/trendsReport?hl=en&q=${keywords}&tz=${timezone}&content=1
在哪里
是一个编码的空格分隔的关键字列表${keywords}
是Etc/GMT*格式的编码时区${timezone}
<div id="reportContent" Class="report-content"></div>
Element report = doc.select(div.report-content).first();
https://www.google.com/trends/trendsReport?hl=en&q=${keywords}&tz=${timezone}&content=1
String myKeywords = "ice cream";
String myTimezone = "Etc/GMT+2";
String url = "https://www.google.com/trends/trendsReport?hl=en&q=" + URLEncoder.encode(keywords, "UTF-8") +"&tz="+URLEncoder.encode(myTimezone, "UTF-8")+"&content=1";
Document doc = Jsoup.connect(url).timeout(10000).get();
Element scriptElement = doc.select("div#TIMESERIES_GRAPH_0-time-chart + script").first();
if (scriptElement==null) {
throw new RuntimeException("Unable to locate trends data.");
}
String jsCode = scriptElement.html();
// parse jsCode to extract charData...