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

yipeiwu_com5年前服务器

本文实例讲述了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的Twisted框架实现一个简单的服务器

预览   twisted是一个被设计的非常灵活框架以至于能够让你写出非常强大的服务器。这种灵活的代价是需要好通过好几个层次来实现你的服务器, 本文档描述的是Protocol层...

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

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

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

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

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

python 从远程服务器下载日志文件的程序

复制代码 代码如下:import osimport sysimport ftplibimport socket #####################################...

Spring Cloud微服务架构简介

Spring Cloud微服务架构简介

什么是微服务微服务架构风格是一种将一个单一应用程序开发为一组小型服务的方法,每个服务运行在自己的进程中,服务间通信采用轻量级通信机制(通常用HTTP资源API)。这些服务围绕业务能力构建并且可通过全自...