Python基于scrapy采集数据时使用代理服务器的方法
作者:pythoner 时间:2022-06-03 08:37:04
本文实例讲述了Python基于scrapy采集数据时使用代理服务器的方法。分享给大家供大家参考。具体如下:
# To authenticate the proxy,
#you must set the Proxy-Authorization header.
#You *cannot* use the form http://user:pass@proxy:port
#in request.meta['proxy']
import base64
proxy_ip_port = "123.456.789.10:8888"
proxy_user_pass = "awesome:dude"
request = Request(url, callback=self.parse)
# Set the location of the proxy
request.meta['proxy'] = "http://%s" % proxy_ip_port
# setup basic authentication for the proxy
encoded_user_pass=base64.encodestring(proxy_user_pass)
request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass
希望本文所述对大家的python程序设计有所帮助。
标签:Python,scrapy
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现基于KNN算法的笔迹识别功能详解
2021-06-18 13:15:08
![](https://img.aspxhome.com/file/2023/6/72036_0s.png)
The Story of Mr.Gray — Web 交互设计“灰色”的8类应用
2009-12-30 16:57:00
![](https://img.aspxhome.com/file/UploadPic/20101/11/mr-gray-01-93s.jpg)
ASP.NET 2.0防止同一用户同时登录
2007-10-03 14:30:00
如何做一个计数器并让人家申请使用?
2010-07-11 21:13:00
Sql Server2005对现有数据进行分区具体步骤
2008-06-26 13:18:00
关于python pygame游戏进行声音添加的技巧
2023-06-25 16:12:30
解析PHP中VC6 X86和VC9 X86的区别及 Non Thread Safe的意思
2023-11-06 13:11:37
牢不可破的九宫格布局
2009-07-24 12:40:00
![](https://img.aspxhome.com/file/UploadPic/20097/24/jiougongge1-43s.gif)
设计输入了些什么?
2008-04-02 11:16:00
8行代码实现Python文件去重
2023-11-20 14:47:35
![](https://img.aspxhome.com/file/2023/4/64334_0s.jpg)
最新屏蔽百度快照的方法
2009-07-06 14:37:00
Python使用Asyncio进行web编程方法详解
2022-08-11 17:03:56
![](https://img.aspxhome.com/file/2023/8/70798_0s.png)
PHP的PDO大对象(LOBs)
2023-06-07 06:45:36
基于display:table的CSS布局
2008-10-30 10:38:00
![](https://img.aspxhome.com/file/UploadPic/200810/30/display-table1-44s.jpg)
几款优秀的中文字体设计
2008-03-24 17:25:00
![](https://img.aspxhome.com/file/UploadPic/20083/24/2008324173030354s.jpg)
kNN算法python实现和简单数字识别的方法
2023-09-05 21:44:36
![](https://img.aspxhome.com/file/2023/1/72751_0s.png)
网站防止采集方法全攻略
2007-09-05 19:57:00
JavaScript 解析 Cookie 的函数
2007-11-08 11:58:00
让你一文弄懂Pandas文本数据处理
2023-07-17 19:12:08
![](https://img.aspxhome.com/file/2023/8/61218_0s.png)
python中加背景音乐如何操作
2023-11-09 02:54:51