写到scrapy 中间件
import base64
""" 阿布云ip代理配置,包括账号密码 """
proxyServer = "http://http-dyn.abuyun.com:9020"
proxyUser = "HWFxxx"
proxyPass = "CB8Dxxx"
# for Python3
proxyAuth = "Basic " + base64.urlsafe_b64encode(bytes((proxyUser + ":" + proxyPass), "ascii")).decode("utf8")
class aby(object):
""" 阿布云ip代理配置 """
def process_request(self, request, spider):
request.meta["proxy"] = proxyServer
request.headers["Proxy-Authorization"] = proxyAuth
然后setting里面
打开 DOWNLOADER_MIDDLEWARES