Java JSoup error fetching URL

后端 未结 1 1057
南笙
南笙 2020-12-21 03:33

I\'m creating an application which will enable me to fetch values from a specific website to the console. The value is from a element and I\'m usin

相关标签:
1条回答
  • 2020-12-21 04:05

    Set the user-agent header:

    .userAgent("Mozilla")
    

    Example:

    Document document = Jsoup.connect("https://stackoverflow.com/questions/11970938/java-html-parser-to-extract-specific-data").userAgent("Mozilla").get();
    Elements elements = document.select("span.hidden-text");
    for (Element element : elements) {
      System.out.println(element.text());
    }
    

    Stack Exchange

    Inbox

    Reputation and Badges

    source: https://stackoverflow.com/a/7523425/1048340


    Perhaps this is related: https://meta.stackexchange.com/questions/277369/a-terms-of-service-update-restricting-companies-that-scrape-your-profile-informa

    0 讨论(0)
提交回复
热议问题