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程序设计有所帮助。

相关文章

Python实现简单的代理服务器

本文实例讲述了Python实现简单的代理服务器。分享给大家供大家参考。具体如下: 具备简单的管理功能,运行后 telnet localhost 9000 端口可以进行管理主要功能就是做包...

基于腾讯云服务器部署微信小程序后台服务(Python+Django)

基于腾讯云服务器部署微信小程序后台服务(Python+Django)

一 前言 微信小程序,相信大家早已熟知,它是一种无需下载安装即可使用的轻型应用,具有跨平台和接近 Native App 性能体验的优势。从开发模式上说,它是前后端分离的,微信小程序负责实...

使用PHP获取当前url路径的函数以及服务器变量

PHP获取当前url路径的函数及服务器变量:代码:复制代码 代码如下:<?php$path = /usr/opt/../ect/abcd;echo $_SERVER['DOCUME...

php模拟服务器实现autoindex效果的方法

php模拟服务器实现autoindex效果的方法

本文实例讲述了php模拟服务器实现autoindex效果的方法。分享给大家供大家参考。具体实现方法如下: 1.PHP代码如下: 复制代码 代码如下:<?php //文件浏...

深入Memcache的Session数据的多服务器共享详解

一相关介绍1.memcache + memcache的多服务器数据共享的介绍,请参见http://www.guigui8.com/index.php/archives/206.html2...