我正在尝试使用 Jsoup 解析此网站:http://www.listofnewspapers.com/2014/04/site-map.html但我收到此错误:
For 'http://www.listofnewspapers.com/2014/04/site-map.html': HTTP error fetching URL"
我相信错误发生在connect(URL).get()
。
出于调试目的,我打印了状态代码,得到了 200
。
我尝试了多个其他网站,它们连接得很好。
最佳答案
用户代理似乎被过滤了。尝试设置一个:
Jsoup.connect(URL).userAgent("Mozilla").get()
关于java - 获取 URL 时发生 HTTP 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44349297/