gpt4 book ai didi

python - 使用带有 scrapy-splash 的代理

转载 作者:太空狗 更新时间:2023-10-30 01:57:10 24 4
gpt4 key购买 nike

我正在尝试将代理 (proxymesh) 与 scrapy-splash 一起使用。我有以下(相关)代码

PROXY = """splash:on_request(function(request)
request:set_proxy{
host = http://us-ny.proxymesh.com,
port = 31280,
username = username,
password = secretpass,
}
return splash:html()
end)"""

并在 start_requests 中

def start_requests(self):
for url in self.start_urls:
print url
yield SplashRequest(url, self.parse,
endpoint='execute',
args={'wait': 5,
'lua_source': PROXY,
'js_source': 'document.body'},

但是好像不行。 self.parse 根本没有被调用。如果我将端点更改为“render.html”,我会使用 self.parse 方法,但是当我检查 header (response.headers) 时,我可以看到它没有通过代理。我确认当我设置 http://checkip.dyndns.org/作为起始 url 并在解析响应时看到我的旧 ip 地址。

我做错了什么?

最佳答案

您应该向 SplashRequest 对象添加“代理”参数。

def start_requests(self):
for url in self.start_urls:
print url
yield SplashRequest(url, self.parse,
endpoint='execute',
args={'wait': 5,
'lua_source': PROXY,
'js_source': 'document.body',
'proxy': 'http://proxy_ip:proxy_port'}

关于python - 使用带有 scrapy-splash 的代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43646438/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com