Python基于scrapy采集数据时使用代理服务器的方法

yipeiwu_com6年前服务器

本文实例讲述了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程序设计有所帮助。

相关文章

PHP 高并发和大流量框架解决方案

一、高并发的概念在互联网时代,并发,高并发通常是指并发访问。也就是在某个时间点,有多少个访问同时到来。二、高并发架构相关概念1、QPS (每秒查询率) : 每秒钟请求或者查询的数量,在互联网领域,指每...

python实现从ftp服务器下载文件的方法

本文实例讲述了python实现从ftp服务器下载文件的方法。分享给大家供大家参考。具体实现方法如下: import ftplib ftp = ftblib.FTP("ftp.your...

php获取服务器信息的实现代码

复制代码 代码如下:<html><head><meta http-equiv="content-type" content="text/html; char...

python通过邮件服务器端口发送邮件的方法

本文实例讲述了python通过邮件服务器端口发送邮件的方法。分享给大家供大家参考。具体实现方法如下: fromAddress = 'sender@example.com' toAdd...

python3.8 微信发送服务器监控报警消息代码实现

python3.8 微信发送服务器监控报警消息代码实现

这篇文章主要介绍了python3.8 微信发送服务器监控报警消息代码实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 python版...