org.jsoup.HttpStatusException: HTTP error fetching URL. Status=403 爬取网站出现403错误
2017-10-17 11:18
671 查看
爬取网站的时候 conn = Jsoup.connect(url).timeout(5000).get();直接用get方法,有些网站可以正常爬取。
但是有些网站报403错误,403是一种在网站访问的过程中,常见的错误提示。表示资源不可用,服务器理解客户对的请求,但是拒绝处理它,通常由服务器上文件或者目录的权限设置导致的web访问错误。
解决方法无非就是从这几个角度:useragent,referer,token,cokkie
所以我们给连接添加模拟浏览器的header:
然后再执行conn.get()
就可以得到数据了。
推荐一款特别好用的抓包工具: fiddler
但是有些网站报403错误,403是一种在网站访问的过程中,常见的错误提示。表示资源不可用,服务器理解客户对的请求,但是拒绝处理它,通常由服务器上文件或者目录的权限设置导致的web访问错误。
解决方法无非就是从这几个角度:useragent,referer,token,cokkie
所以我们给连接添加模拟浏览器的header:
conn = Jsoup.connect(url).timeout(5000); conn.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); conn.header("Accept-Encoding", "gzip, deflate, sdch"); conn.header("Accept-Language", "zh-CN,zh;q=0.8"); conn.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
然后再执行conn.get()
就可以得到数据了。
推荐一款特别好用的抓包工具: fiddler
相关文章推荐
- Jsoup 发送post请求 org.jsoup.HttpStatusException: HTTP error fetching URL. Status=404, URL=https:
- org.jsoup.HttpStatusException:HTTP error fetching URL. Status=500, URL=******************
- Tomcat7出现HTTP Status 500 - java.lang.ClassCastException: org.apache.jasper.el.ELContextImpl cannot be cast to org.apache.jasper.el.ELContextImpl的解决
- JSOUP获取网页数据返回403错误(403 error loading URL,connection类)
- Tomcat7.0.67 登陆首页出现HTTP Status 500 - java.lang.ClassCastException: org.apache.jasper.el.ELContextImp
- Tomcat7出现HTTP Status 500 - java.lang.ClassCastException: org.apache.jasper.el.ELContextImpl cannot b
- 调用webservice,出现错误:Uncaught SoapFault exception: [HTTP] Error Fetching http headers
- JSOUP获取网页数据返回403错误(403 error loading URL,connection类)
- JSOUP获取网页数据返回403错误(403 error loading URL,connection类)
- Tomcat7出现HTTP Status 500 - java.lang.ClassCastException: org.apache.jasper.el.ELContextImpl cannot be cast to org.apache.jasper.
- Tomcat7出现HTTP Status 500 - java.lang.ClassCastException: org.apache.jasper.el.ELContextImpl cannot b
- iOS UIWebView 载入https 网站出现NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL,
- Tomcat7出现HTTP Status 500 - java.lang.ClassCastException: org.apache.jasper.el.ELContextImpl cannot b
- iOS UIWebView 载入https 网站出现NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL,
- Qt error ------ 出现Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly
- [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
- HTTP Status 500 - java.lang.ClassNotFoundException: org.apache.jsp.hello_jsp
- 本地调试WCF程序出现错误:AddressAccessDeniedException: HTTP could not register URL
- HTTP Status 500 - java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.pages.index.index_jsp