1
votes

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();
1
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
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 :ppdai.com/blacklist/2014xiaocainiao

1 Answers

0
votes

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();