Java 如何使用jsoup访问子类

Java 如何使用jsoup访问子类,java,web-crawler,jsoup,Java,Web Crawler,Jsoup,我想访问此网页:并提取中线图中的数据。html文件是(在这里,我只粘贴我使用的部分): 打印“中心”类时,可以得到除“报表内容”之外的所有子类内容,打印“报表内容”时,结果只有: <div id="reportContent" Class="report-content"></div> 但仍然根本不起作用。我如何在这里获取脚本中的数据?我感谢你的帮助 尝试通过Id获取相同的标签,您将获得完整的标签请尝试以下url: https://www.google.co

我想访问此网页:并提取中线图中的数据。html文件是(在这里,我只粘贴我使用的部分):

打印“中心”类时,可以得到除“报表内容”之外的所有子类内容,打印“报表内容”时,结果只有:

      <div id="reportContent" Class="report-content"></div>

但仍然根本不起作用。我如何在这里获取脚本中的数据?我感谢你的帮助

尝试通过Id获取相同的标签,您将获得完整的标签

请尝试以下url:

https://www.google.com/trends/trendsReport?hl=en&q=${keywords}&tz=${timezone}&content=1
在哪里

  • ${keywords}
    是一个编码的空格分隔的关键字列表
  • ${timezone}
    是Etc/GMT*格式的编码时区

示例代码 参考资料:


谢谢!当我使用id“doc.select(div.reportContent)”时,结果为空。当我使用类“doc.select(div.report-content)”时,结果没有内容。然后我也无法在这个类中获取脚本。您是否尝试过getElementById(“reportMain”)?请参阅。非常感谢!太神奇了~~!
      <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...