org.jsoup.HttpStatusException: HTTP error fetching URL. Status=403
爬取网站的时候 conn = Jsoup.connect(url).timeout(5000).get();直接用get方法,有些网站可以正常爬取。
但是有些网站报403错误,403是一种在网站访问的过程中,常见的错误提示。表示资源不可用,服务器理解客户对的请求,但是拒绝处理它,通常由服务器上文件或者目录的权限设置导致的web访问错误。
解决方法无非就是从这几个角度:useragent,referer,token,cokkie
所以我们给连接添加模拟浏览器的header:
- <span style="white-space:pre;"> </span>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()
就可以得到数据了。
org.jsoup.HttpStatusException: HTTP error fetching URL. Status=403的更多相关文章
- spring security There was an unexpected error (type=Forbidden, status=403).
https://blog.csdn.net/qq_27093097/article/details/83190240 spring security There was an unexpected e ...
- jenkins git can't work ERROR: Timeout after 10 minutes ERROR: Error fetching remote repo 'origin'
Started by user Allen Running as Allen Building remotely on MISTestSrv2 (MIS) in workspace C:\jenkin ...
- 【ERROR】使用jquery的ajax出现error:readyState=4,status=500
使用jquery的ajax出现error:readyState=4,status=500,ajax代码如下: $.ajax({ url : "../toBeFinMisManage/show ...
- 解决Jenkins上git出现的“ERROR: Error fetching remote repo 'origin'”问题
今天对清掉了Jenkins中项目的工作空间,结果构建出现“ERROR: Error fetching remote repo 'origin'”问题:网上各种找也没找到解决这个问题的方法. 后来看错误 ...
- kinaba 安装踩坑: FATAL Error: [elasticsearch.url]: definition for this key is missing
操作系统:Linux kibana 版本: 7.4.0 1. 在/etc/yum.repos.d/ 下新建 kibana.repo 配置 yum 源地址 内容如下: [root@localhost ...
- kinaba 安装踩坑: FATAL Error: [elasticsearch.url]: definition for this key is missing 转
安装 https://www.jianshu.com/p/875457cb8da6 操作系统:Linux kibana 版本: 7.4.0 1. 在/etc/yum.repos.d/ 下新建 ...
- eth0: error fetching interface information: Device not found
转载,原文出处:http://zh888.blog.51cto.com/1684752/775447 亲测有效,感谢作者!!! ----------------------------分割线----- ...
- Error fetching https://gems.ruby-china.org/: bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz) 报错解决办法
执行换源操作 gem source -a https://gems.ruby-china.org/ 时报错: Error fetching https://gems.ruby-china.org/: ...
- Ubuntu urllib2.URLError:<urlopen error unknown url type:https>
描述: python中urllib2 下载网页时,出现错误urllib2.URLError:<urlopen error unknown url type:https> 解决方法: pyt ...
随机推荐
- ansible1
前期工作: 第一步:下载epel源 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 第二步: ...
- 安装scrapy时遇到的问题
会报错,安装这个试试: pip install cryptography --force-reinstall
- 24 【python入门指南】class
一.类 1.1,构造函数,析构函数 #!/bin/python class dog(): def __init__(self, age, name): self.age = age self.name ...
- TZOJ 2546 Electricity(去掉割点后形成的最大连通图数)
描述 Blackouts and Dark Nights (also known as ACM++) is a company that provides electricity. The compa ...
- f5基本介绍
1.信息查看 1)登录: https://10.160.100.10 f5有2台,做HA IP地址分别为10.160.100.3和10.160.100.2 10.160.100.10为虚拟地址 2)基 ...
- c#: Noto Sans字体如何支持韩文
1.源起: VCU10项目,使用了Noto Sans字体,的确漂亮.但验证在win7下,其显示韩文为乱码,颇为头痛. 其界面显示如图: 度娘之,得Noto Sans又有CJK字体,顾名思义,其为支持中 ...
- 项目总结08:spring quartz 定时器Demo
将定时器用到的quartz.jar放在lip文件下 quartz.xml文件(完整) <?xml version="1.0" encoding="UTF-8&quo ...
- 《基于Nginx的中间件架构》学习笔记---1.环境配置
一.环境调试确认 (四项确认) 1.确认系统网络 ping www.baidu.com 2.确认yum可用 yum list|grep gcc 3.确认关闭iptables规则 iptables -L ...
- cherry-pick 命令
拣选会提取某次提交的补丁,之后尝试将其重新应用到当前分支上. 这种方式在你只想引入特性分支中的某个提交时很有用. 假设你的项目提交历史如下: 如果你希望将提交 e43a6 拉取到 master 分支, ...
- sqlserver数据库命名规则
sqlserver数据库命名规则: (1)第一个字符必须是字母或“_”.“@”.“#” (2)数据库名称不能是T-SQL的保留字 (3)不允许嵌入空格或其他特殊字符