当前位置:网站首页>网络爬虫错误
网络爬虫错误
2022-08-10 01:34:00 【bamboogz99】
在使用urllib中的request方法时,系统返回HTTPerror,但是没有给出错误代码
重新写了一段代码,用来显示具体错误:
# 异常处理
from urllib import request,error
try:
response = urllib.request.urlopen('https://movie.douban.com/top250')
except error.HTTPError as e:
print(e.reason,e.code,e.headers,sep='\n') # 使用httperror判断
这里访问的是豆瓣,结果返回错误418,查了下是反爬虫的。
处理办法:不是一次请求整个网页,而是加入header选项,只读取头部,如下:
第二个问题是,如何读取多页的信息,此时通过观察,得知douban的页面链接中包含了页码信息,用for循环配合页码即可:
边栏推荐
- 数据库治理利器:动态读写分离
- HCIP——综合交换实验
- 【每日一题】1413. 逐步求和得到正数的最小值
- UXDB现在支持函数索引吗?
- 在蓝图中给组件动态加子Actor组件
- unity 报错 Unsafe code may only appear if compiling with /unsafe. Enable “Allow ‘unsafe‘ code“ in Pla
- [LeetCode] Find the sum of the numbers from the root node to the leaf node
- 华为HCIE云计算之FC添加ipsan数据存储
- [转] Typora_Markdown_图片标题(题注)
- 3dmax如何制作模型走路动画
猜你喜欢
随机推荐
基于C51的中断控制
解决sed替换文本,里面含有“/“、“#”等特殊字符的问题
web开发概述
《GB39732-2020》PDF下载
使用IDEA的PUSH常见问题
你有对象类,我有结构体,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang结构体(struct)的使用EP06
2022年8月8日-2022年8月15日,ue4视频教程+插件源码()
罗彻斯特大学 | 现在是什么序列?蛋白质序列的贝叶斯优化的预训练集成
[语法糖] 关于类别字符串到类别数字id的映射
Maya制作赛博朋克机器人模型
Unity reports Unsafe code may only appear if compiling with /unsafe. Enable “Allow ‘unsafe’ code” in Pla
OpenCV图像处理学习三,Mat对象构造函数与常用方法
【wpf】拖拽的简单实现
Linux(Centos7)服务器中配置Mysql主从数据库,以及数据库的安装,防火墙操作
hint: Updates were rejected because the tip of your current branch is behind hint: its remote counte
Sikuli 基于图形识别的自动化测试技术
Unity碰撞和触发
具有多孔光纤的偏振分束器
Sikuli's Automated Testing Technology Based on Pattern Recognition
[Syntax sugar] About the mapping of category strings to category numeric ids