【发布时间】:2016-04-19 03:52:16
【问题描述】:
我想访问这个网页:https://www.google.com/trends/explore#q=ice%20cream 并在中心线图中提取数据。 html文件是(这里,我只粘贴我使用的部分。):
<div class="center-col">
<div class="comparison-summary-title-line">...</div>
...
<div id="reportContent" class="report-content">
<!-- This tag handles the report titles component -->
...
<div id="report">
<div id="reportMain">
<div class="timeSection">
<div class = "primaryBand timeBand">...</div>
...
<div aria-lable = "one-chart" style = "position: absolute; ...">
<svg ....>
...
<script type="text/javascript">
var chartData = {...}
我使用的数据存储在脚本部分(最后一行)。我的想法是先获取类“report-content”,然后选择脚本。我的代码如下:
String html = "https://www.google.com/trends/explore#q=ice%20cream";
Document doc = Jsoup.connect(html).get();
Elements center = doc.getElementsByClass("center-col");
Element report = doc.getElementsByClass("report-content");
System.out.println(center);
System.out.println(report);
当我打印“中心”类时,我可以获得除“报告内容”之外的所有子类内容,而当我打印“报告内容”时,结果只是:
<div id="reportContent" Class="report-content"></div>
我也试试这个:
Element report = doc.select(div.report-content).first();
但仍然无法正常工作。我怎么能在这里得到脚本中的数据?感谢您的帮助!!!
【问题讨论】:
标签: java web-crawler jsoup