Java JSoup error fetching URL -


i'm creating application enable me fetch values specific website console. value <span> element , i'm using jsoup.

my challenge has error:

error fetching url

here java code:

public class testsl {     public static void main(string[] args) throws ioexception {         document doc = jsoup.connect("https://stackoverflow.com/questions/11970938/java-html-parser-to-extract-specific-data").get();         elements spans = doc.select("span[class=hidden-text]");         (element span: spans) {             system.out.println(span.text());         }     } } 

and here error on console:

exception in thread "main" org.jsoup.httpstatusexception: http error fetching url. status=403, url=java html parser extract specific data? @ org.jsoup.helper.httpconnection$response.execute(httpconnection.java:590) @ org.jsoup.helper.httpconnection$response.execute(httpconnection.java:540) @ org.jsoup.helper.httpconnection.execute(httpconnection.java:227) @ org.jsoup.helper.httpconnection.get(httpconnection.java:216) @ testsl.main(testsl.java:19)

what doing wrong , how can resolve it?

set 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"); (element element : elements) {   system.out.println(element.text()); } 

stack exchange

inbox

reputation , badges

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


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


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -