How to retrieve content from specific HTML page through Java -


I am working in an application to parse html content for any website, but today, Found exceptions for non-affiliation. I am trying to get content from this url: and I always get the following error: java.io.IOException: The server returned the HTTP response code: 403. I am using the JSOUP library. I tried other 2 options without Jasup option, but it did not succeed. This page can be accessed from a browser but not from Java. Can you help with some tips?

Thanks

  Document Doctor; String url = "http://tomfishburne.com/2014/09/socialmedia.html"; Try {feedback feedback = jsoup.connect (url) .ignoreContentType (right) .userAgent ("Mozilla / 5.0 (Windows NT 6.1, Win64; 64; LV / 2500) 12000). FollowRedirects (true) .execute (); Doc = response.parse (); } Hold (Exception E) {Try {doc = Jsoup.connect (url) .userAgent ("Mozilla / 5.0 (Windows NT 6.1; WOW64; RV: 25.0) Lizard / 20,100,101 Firefox / 25.0") .Get () ; } Hold (IOException e1) {try url2 = new URL (url); HttpURLConnection conn = (HttpURLConnection) url2 .openConnection (); Conn.setRequestProperty ("user-agent", "Mozilla / 5.0 (Windows NT 6.3; WOW64) AppleWebKit / 537.36 (KHTML, like Lizard) Chrome / 37.0.2062.124 Safari / 537.36"); In BufferedReader; In = new buffed reader (new inputtreamreader (conn.getInputStream (), "UTF-8"); } Hold (UnsupportedEncodingException e2) {} Grip (IOException E2) {// This exception is always thrown due to error code 403}}}}  

You have to add ignoreHttpErrors (true) to make your call: eg:

  document Document = jsoup.connect (url) .userAgent ('Mozilla / 5.0 (X11, Linux x86_64, RV .: 32.0) Lizard / 20,100,101 Firefox / 32.0') .ignoreHttpErrors (true) .get ()  < / Pre> 

It has been found that this website is always prohibited 403, even when it comes Access it from a web browser - for example you can see it in firebug.

I have created a running Groove script - it works well.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -