-
代理操作
-
在爬虫中 代理就是代理服务器
-
用来转发请求和响应的
-
爬虫对服务器发起高频请求,那么服务器会检测到这样的一个异常的行为。会对设备限制,无法再次请求。
-
ip被禁,就可以使用代理服务器进行请求转发,破解IP被禁反爬机制。
-
代理服务器分类
- 透明代理:服务器知道你使用了代理机制,也知道你真实IP
- 匿名代理:知道你使用代理,但是不知道真实IP
- 高匿代理:不知道你用代理,也不知道真实IP
-
代理的类型
- https:代理只能转发https协议的请求
- http:转发http的请求
-
-
实例代码
url = "" page_text = requests.get(url, headers=headers).text tree = etree.HTML(page_text) proxy_lst = tree.xpath("//div[@class='']//text()") # 以上步骤是从代理服务器提取IP地址 http_proxy = [] for proxy in proxy_lst: dic = { 'http': proxy } http_proxy.append(dic) print(http_proxy) url = "" ips = [] for page in range(1, 11): new_url = format(url % page) page_text = requests.get(url=new_url, headers=headers, proxies={'http':ip:port}).text # 另外可以随机取 proxies = random.choice(http_proxy) tree = etree.HTML(page_text) # 在xpath表达式中不可以出现tbody标签 tr_list = tee.xpath('//*[@id="ip_list"]') for tr in tr_lst: ip = tr.xpath() ips.append(ip) print(len(ips))
-
补充 异步爬虫
- 基于线程池的异步爬虫
- 基于单线程+多任务的异步爬虫(实际中很少用)
爬虫---04.代理操作
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:缓冲区溢出攻击
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
04. 函数
在Python编程中,函数是一项强大而灵活的工具,它不仅能够使代码更有组织性,还能提高代码的重用性。函数是组织好的,可重复使用
python java 服务器 Python 递归 -
04.目录设计
目录排版以设计好,直接调用目录模板直接可以使用,使用简单
python 办公自动化 pdf 计算机技术 office -
LCP 04. 覆盖
个棋盘覆.
算法 权重 最大匹配 二分图 -
04. Idea集成Docker
上一节中,我们介绍了Dockerfile的
docker 云原生 linux 运维 Dockerfile -
04. Django基础:路由配置
路由配置
数据 正则表达式 django -
SQL Server存储引擎 - 04. 数据
一. 文件 二. 页
数据页 行偏移量 -
数据结构 --- 04.排序算法
一.冒泡 二.选择 三.插入 四.希尔 五.快排
选择排序 数据 插入排序 背景颜色 -
ios swiper change事件
作者:汪娇娇 日期:2018年3月10日 一、介绍先用几张图来和大家描述一下什么是图片预览效果吧。 图一:图片列表;图二:点击列表中 “小猫” 这张图片,会弹出图二这样的预览图;图三:对图二向左或向右滑动会出现图三的样子,滑动的距离和区域小于某个值时,图片还是会回到当前这张图,超过某个值了,就会滑到上一张图或下一张图;
ios swiper change事件 javascript json ViewUI css