1.分析:

如果用 urllib.request.urlopen 方式打开一个URL,服务器端只会收到一个单纯的对于该页面访问的请求,但是服务器并不知道发送这个请求使用的浏览器,操作系统,硬件平台等信息,而缺失这些信息的请求往往都是非正常的访问,例如爬虫.
有些网站验证请求信息中的UserAgent(它的信息包括硬件平台、系统软件、应用软件和用户个人偏好),如果UserAgent存在异常或者是不存在,那么这次请求将会被拒绝(如上错误信息所示)
所以可以尝试在请求中加入UserAgent的信息
方案:
对于Python 3.x来说,在请求中添加UserAgent的信息非常简单,代码如下:
可以在请求加上头信息,伪装成浏览器访问User-Agent,具体的信息可以通过火狐的FireBug插件查询

headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}  
req = request.Request(url=chaper_url, headers=headers)  
page  = request.urlopen(req).read() 
 
参考:https://www.cnblogs.com/lixiaolun/p/4773433.html 

python3 raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 403: Forbid的更多相关文章

  1. urllib.error.HTTPError: HTTP Error 403: Forbidden

    问题:  urllib.request.urlopen() 方法经常会被用来打开一个网页的源代码,然后会去分析这个页面源代码,但是对于有的网站使用这种方法时会抛出"HTTP Error 40 ...

  2. python抓取不得姐动图(报错 urllib.error.HTTPError: HTTP Error 403: Forbidden)

    抓取不得姐动图(报错) # -*- coding:utf-8 -*- #__author__ :kusy #__content__:文件说明 #__date__:2018/7/23 17:01 imp ...

  3. python3 安装scrapy Exception: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 1006, in check_if_exists解决方法

    错误代码: Exception: Traceback (most recent call last): File , in check_if_exists self.satisfied_by = pk ...

  4. python3.6.5 + selenium +VS Code 运行报错:Unable to find a matching set of capabilities的解决

    在python3.6.5 + selenium +VS Code 环境中,在class的__init__ 方法初始化火狐浏览器时出现以下错误: 发生异常: selenium.common.except ...

  5. Python3安装turtle提示错误:Command "python setup.py egg_info" failed with error code 1

    Python3安装turtle提示错误:Command "python setup.py egg_info" failed with error code 1 Python3.5安 ...

  6. python3 使用urllib报错urlopen error EOF occurred in violation of protocol (_ssl.c:841)

    python3源码: import urllib.request from bs4 import BeautifulSoup response = urllib.request.urlopen(&qu ...

  7. raise RuntimeError("autoconf error") RuntimeError: autoconf error

    pip 安装模块时遇到下错误,没有粘贴全,差不多都是这样.这个情况是 pip 安装模块 需要 gcc 及 python-devle 支持, ubuntu 是 python-dev ,使用Yum 安装即 ...

  8. centos 7 运行Quartus ii 17.0 标准版,下载程序时遇到错误error (209053): unexpected error in jtag server -- error code 89

    对于错误error (209053): unexpected error in jtag server -- error code 89,它产生的原因在于,在linux系统下,Quartus ii的驱 ...

  9. 启动链码报rpc error: code = Unimplemented desc = unknown service protos.ChaincodeSupport start error

    参考链接:https://stackoverflow.com/questions/48007519/unimplemented-desc-unknown-service-protos-chaincod ...

随机推荐

  1. Codeforces339D(SummerTrainingDay06-A 线段树)

    D. Xenia and Bit Operations time limit per test:2 seconds memory limit per test:256 megabytes input: ...

  2. sass在vue注意的地方

    当用@import导入vue页面的时候,在sass/scss文件里面的url,路径开始就是导入的vue位置. 当前目录结构 App.vue 我在App.vue导入了public.scss,那在publ ...

  3. 结束autocad异常进程

    近日在做CAD自动化数据处理,程序在服务器上运行,运行时间长了会发生异常“autocad application 已停止工作”,这个时候需要通过守护程序去重启CAD, 通过CMD命令“@taskkil ...

  4. 有关 Android Studio 重复引入包的问题和解决方案

    虽然相同包名相同类名的文件在不同 SDK 中出现的概率极低,但是一旦出现,处理起来就比较棘手.最好的解决方案就是联系提供 SDK 的技术人员反映问题,让其通过修改源码重新打包一个新的 Jar 包. 还 ...

  5. KeyPress 和KeyDown 、KeUp之间的区别

    前几天,在写完一个功能模块上线测试的时候,出现了一个诡异的问题.input 框在输入查询内容之后,按回车键居然有两种不同的表现形式(input 框没有绑定键盘事件),谷歌和火狐功能正常,但IE在按了回 ...

  6. LeetCode 题解之Linked List Cycle II

    1.题目描述 2.问题分析 使用快慢指针方法判断链表是否有环,然后寻找环开始的节点. 3.代码 ListNode *detectCycle(ListNode *head) { if( head == ...

  7. VMWare12虚拟机实现主客机间的文件拖拽(复制粘贴)和文件夹共享

    版本: 主机:Windows 7 64位旗舰版 虚拟机: VMWare 12 + Windows 7 64位旗舰版 VMWare pro 12 + Ubuntu16.04LTS 64位 注:由于VMW ...

  8. Prometheus Node_exporter 之 Memory Detail Vmstat Counters

    Memory Detail Vmstat Counters 1. Memory Page Active type: GraphUnit: shortLabel: PagesActive_anon - ...

  9. Oracle EBS 用户职责人员取值

    SELECT fu.user_name 用户名, fu.description 用户说明, fu.start_date 用户启用日期, fu.end_date 用户终止日期 --,fu.employe ...

  10. MySQL索引背后的数据结构及算法原理(employees实例)

    摘要 http://blog.codinglabs.org/articles/theory-of-mysql-index.html 本文以MySQL数据库为研究对象,讨论与数据库索引相关的一些话题.特 ...