1

Jsoup catch data appear unknowhost exception ,and can`t ping the website ,but my web browser can visit

I try change the userAgent,but it doesn`t work! Here are the userAgent before:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36

Here the my browser userAgent which can visit:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36

Although I change the userAgent,but it remains the unknowhost exception !

Here is my code:

doc = Jsoup.connect(source+"/blacklist/"+y+"_m0_p"+p) //     
                    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36")  //
                    .timeout(5000 * tryCount) //
                    .get();
Stephan
  • 41,764
  • 65
  • 238
  • 329
xiaocainiao
  • 33
  • 1
  • 5
  • can you share the URL which you are trying to reach? Also please post the Java code that you use to access the site. What is the StackTrace? – luksch Aug 13 '15 at 08:07
  • doc = Jsoup.connect(source+"/blacklist/"+y+"_m0_p"+p) .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36") .timeout(5000 * tryCount) .get(); ~~~~~~~~~~~~~~~~the web site :http://www.ppdai.com/blacklist/2014 – xiaocainiao Aug 13 '15 at 12:30

1 Answers1

0

but my web browser can visit

Check if your browser uses a proxy. If so, tell Jsoup to use the same proxy:

String host = "..."; // Proxy host
String port = "..."; // Proxy port

System.setProperty("http.proxyHost", host);
System.setProperty("http.proxyPort", port);

System.setProperty("https.proxyHost", host);
System.setProperty("https.proxyPort", port);

Document doc = Jsoup.connect(source+"/blacklist/"+y+"_m0_p"+p) //     
                    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36")  //
                    .timeout(5000 * tryCount) //
                    .get();
Stephan
  • 41,764
  • 65
  • 238
  • 329