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

相关文章

【不二】关于affiliate和niche站运营的6条建议

【不二】关于affiliate和niche站运营的6条建议

今天圈友@不二  来给大家分享一些affiliate和英文niche站的的入门玩法,给新手做个科普。 niche,中文一般翻译为利基,可以理解成长尾细分市场,这些细分领域一般来说,市场...

Nginx搭建HTTPS服务器和强制使用HTTPS访问的方法

Nginx搭建HTTPS服务器和强制使用HTTPS访问的方法

HTTPS简介 HTTPS(Hyper Text Transfer Protocol Secure),是一种基于SSL/TLS的HTTP,所有的HTTP数据都是在SSL/TLS协议封装之...

php调整服务器时间的方法

本文实例讲述了php调整服务器时间的方法。分享给大家供大家参考。具体如下: 这里主要使用strftime函数实现这一功能,代码很简单,如下所示: $today = date('Y-m...

Session服务器配置指南与使用经验的深入解析

一.摘要所有Web程序都会使用Session保存数据. 使用独立的Session服务器可以解决负载均衡场景中的Session共享问题.本文介绍.NET平台下建立Session服务器的几种...

详解配置 Apache 服务器支持 PHP 文件的解析

详解配置 Apache 服务器支持 PHP 文件的解析

详解配置 Apache 服务器支持 PHP 文件的解析 【说明】 1. 本例中 Apache 版本为 httpd-2.4.20-x64-vc14 ,安装路径为 E:\Apache24...