永发信息网

scrapy的request的meta参数是什么意思

答案:1  悬赏:20  手机版
解决时间 2021-02-14 16:28
  • 提问者网友:謫仙
  • 2021-02-13 20:28
scrapy的request的meta参数是什么意思
最佳答案
  • 五星知识达人网友:底特律间谍
  • 2021-02-13 21:50
1、在Scrapy工程下新建"middlewares.py":

import base64
# Start your middleware class
class ProxyMiddleware(object):
# overwrite process request
def process_request(self, request, spider):
# Set the location of the proxy
request.meta['proxy'] = ""

# Use the following lines if your proxy requires authentication
proxy_user_pass = "USERNAME:PASSWORD"
# setup basic authentication for the proxy
encoded_user_pass = base64.encodestring(proxy_user_pass)
request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass

2、在项目配置文件里setting.py添加:

DOWNLOADER_MIDDLEWARES = {
'scrapy.contrib.downloadermiddleware.httpproxy.HttpProxyMiddleware': 110,
'pythontab.middlewares.ProxyMiddleware': 100,
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯