JSoup搜索元素

时间:2018-03-09 14:39:42

标签: java html jsoup

我想知道是否有人可以帮助我使用jsoup浏览html页面。

我遇到的最大问题可能是使用.data()函数。当你谷歌搜索“天气”时,我正试图拉动当前的天气。现在我的代码看起来像:

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)
        .data("action", "wob_t")
        //.data("q", "Calgary")
        .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();
     System.out.println(getformPage.getElementsByClass("wob_t"));
   }catch(Exception exception){
      System.exit(0);
   }

我相信除了.data()的正确导航之外我还有其他所有内容。任何帮助,将不胜感激。 谢谢!

0 个答案:

没有答案
相关问题