[英]JSOUP throws url status 503 in Eclipse but URL works fine in browser
In particular, this is with the website amazon.com to be specific. 特别是,这与amazon.com网站是具体的。 I am receiving a 503 error for their domain, but I can successfully parse other domains. 我收到了他们域名的503错误,但我可以成功解析其他域名。
I am using the line 我正在使用这条线
Document doc = Jsoup.connect(url).timeout(30000).get();
to connect to the URL. 连接到URL。
You have to set a User Agent : 您必须设置用户代理 :
Document doc = Jsoup.connect(url).timeout(30000).userAgent("Mozilla/17.0").get();
(Or others; best you choose a browser user agent) (或其他人;最好选择浏览器用户代理)
Else you'll get blocked. 否则你会被封锁。
Please see also: Jsoup: select(div[class=rslt prod]) returns null when it shouldn't 另请参阅: Jsoup:select(div [class = rslt prod])在不应该返回null时返回null
you can try 你可以试试
val ret=Jsoup.connect(url)
.userAgent("Mozilla/5.0 Chrome/26.0.1410.64 Safari/537.31")
.timeout(2*1000)
.followRedirects(true)
.maxBodySize(1024*1024*3) //3Mb Max
//.ignoreContentType(true) //for download xml, json, etc
.get()
it maybe works, maybe amazon.com need followRedirects set to true. 它可能有效,也许amazon.com需要followRedirects设置为true。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.