Python爬虫报错:"HTTP Error 403: Forbidden"

错误原因:主要是由于该网站禁止爬虫导致的,可以在请求加上头信息,伪装成浏览器访问User-Agent。

新增user-agent信息:

headers = {‘User-Agent‘:‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36‘}

 req = request.Request(Spider.url, headers=Spider.headers)

 # 获取到的html的信息

 htmls = request.urlopen(req).read()

谷歌的user-agent查看方法:按F12打开调试工具,在控制台写:javascript:alert(navigator.userAgent),user-agent信息就会弹出

原文地址:https://www.cnblogs.com/syq816/p/12636721.html

时间: 2024-08-05 21:45:07

Python爬虫报错:"HTTP Error 403: Forbidden"的相关文章

git推送到github报错:error: The requested URL returned error: 403 Forbidden while accessing https://github.com

最近使用git命令从github克隆仓库到版本,然后进行提交到github时报错如下: [[email protected] git_test]# git push origin mastererror: The requested URL returned error: 403 Forbidden while accessing https://github.com/jsonhc/git_test.git/info/refs fatal: HTTP request failed 解决办法:参考

爬虫403问题解决urllib.error.HTTPError: HTTP Error 403: Forbidden

一.爬虫时,出现urllib.error.HTTPError: HTTP Error 403: Forbidden Traceback (most recent call last):   File "D:/访问web.py", line 75, in <module>     downHtml(url=url)   File "D:/urllib访问web.py", line 44, in downHtml     html=request.urlre

安装python模块报错 error: command &#39;gcc&#39; failed with exit status 1

最近在安装paramiko模块的时候,总是报错:error: command 'gcc' failed with exit status 1,一开始比较挠头.找了蛮多资料,说的大多都是说缺少Python-devel 包,然而并不是! 最后蛮费劲的找到了一遍短小但就是正确的博文:http://blog.csdn.net/fenglifeng1987/article/details/38057193 —————————————————————— 解决方法: 安装:yum install gcc li

python 网络爬虫报错“UnicodeDecodeError: &#39;utf-8&#39; codec can&#39;t decode byte 0x8b in position”解决方案

Python3.x爬虫, 发现报错"UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1:invalid start byte",一直在找文件的错误,最后经过网友的提示,错误原因竟然是我的报头中有一条: "'Accept-Encoding': 'gzip, deflate'" 这一条是我从Fiddler直接复制过来的,为什么用浏览器可以正常浏览,而用Python模仿就不行呢? 综

urllib.error.HTTPError: HTTP Error 403: Forbidden

问题: urllib.request.urlopen() 方法经常会被用来打开一个网页的源代码,然后会去分析这个页面源代码,但是对于有的网站使用这种方法时会抛出"HTTP Error 403: Forbidden"异常 例如 执行下面的语句时 [python] <span style="font-size:14px;"> urllib.request.urlopen("http://blog.csdn.net/eric_sunah/articl

git push上传代码到gitlab上,报错401或403

之前部署的gitlab代码托管平台,采用ssh方式连接gitlab,在客户机上产生公钥上传到gitlab的SSH-Keys里,则git clone下载和git push上传都没问题,这种方式很安全. 后来应开发同事要求采用http方式连接gitlab,那么首先将project工程的"Visibility Level"改为"Public"公开模式,并且要保证gitlab的http端口像客户机开放. 后面发现了一个问题:http方式连接gitlab后,git clone

pip运行报错Fatal error in launcher: Unable to create process using pip.exe

使用pip的时候报错Fatal error in launcher: Unable to create process using pip.exe 解决办法,升级pip python -m pip install -U pip 或者 python -m pip install --upgrade pip

Android4.4.4 GZIPOutputStream报错:Stream error

在android 4.4.4 机器上使用网友提供的GZipUtils方法进行GZip压缩,但是会一直报错Stream error.错误位置: public static void compress(InputStream is, OutputStream os) throws Exception { GZIPOutputStream gos = new GZIPOutputStream(os); int count; byte data[] = new byte[BUFFER]; while (

解决git提交问题error: The requested URL returned error: 403 Forbidden while accessing

git提交代码时,出现这个错误"error: The requested URL returned error: 403 Forbidden while accessing https" 解决方法: 编辑.git文件夹下的config文件就可以. vim .git/config #改动对于的配置 #原来的url = https://github.com/elitecodegroovy/PhoenixC.git url = https://[email protected]/elitec