Home > Article > Backend Development > Share an example of setting up python scrapy ip proxy
Create a python directory at the same level as spider in the scrapy project and add a py file below with the content
# encoding: utf-8 import base64 proxyServer = 代理服务器地址 ##我的是‘:9010’ # 代理隧道验证信息 这个是在那个网站上申请的 proxyUser = 用户名 proxyPass = 密码 proxyAuth = "Basic " + base64.b64encode(proxyUser + ":" + proxyPass) class ProxyMiddleware(object): def process_request(self, request, spider): request.meta["proxy"] = proxyServer request.headers["Proxy-Authorization"] = proxyAuth 在setting文件中添加
DOWNLOADER_MIDDLEWARES = { '项目名.spider同级文件名.文件名.ProxyMiddleware': 543, } 代码地址
<br>
The above is the detailed content of Share an example of setting up python scrapy ip proxy. For more information, please follow other related articles on the PHP Chinese website!