我之前问了一个问题,我离我的主要目标更近了,但仍然不是我想要的地方。我当前的代码:
try{
Connection formPage = Jsoup.connect("https://www.google.com/search?q=weather&oq=weather&aqs=chrome..69i57j69i61j69i60j0l3.3806j0j7&sourceid=chrome&ie=UTF-8");
formPage.timeout(1000)
.method(Connection.Method.GET)
.userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36")
.execute();
Document getformPage = formPage.get();
//Element getformPage = formPage.getElementById("wob_t");
System.out.println(getformPage.getElementById("wob_t"));
//System.out.println(formPage.request().url());
}catch(Exception exception){
System.exit(0);
}返回null表达式。我希望它能提供当前的天气状况。任何帮助都将不胜感激。谢谢!
发布于 2018-03-13 15:54:13
你可以直接从https://weather.com/en-IN/weather/today/l/18.60,73.71获取详细信息,而不是去谷歌搜索结果,其中18.60,73.71将是你想要详细信息的位置的坐标。


在其中,您可以使用选择器标记 div.today_nowcard-temp来表示温度,也可以使用类似的方法来表示其他细节。
正如@r3dst0rm前面提到的,文档中没有包含详细信息,您可以从https://try.jsoup.org/上尝试使用的谷歌搜索页面中检索该文档
当你需要的细节不存在时,因此你必须尝试其他方法来获得你想要的结果,其中我建议使用一种方法。
https://stackoverflow.com/questions/49226603
复制相似问题