加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 使用scrapy-splash代理

发布时间:2020-12-20 11:59:51 所属栏目:Python 来源:网络整理
导读:我正在尝试使用代理(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
我正在尝试使用代理(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方法,但是当我检查标题(response.headers)时,我可以看到它不会通过代理.我确认当我将http://checkip.dyndns.org/设置为起始URL并在解析响应时看到我的旧IP地址.

我究竟做错了什么?

解决方法

您应该向SplashRequest对象添加’proxy’参数.

def start_requests(self):
    for url in self.start_urls:
        print url
        yield SplashRequest(url,'js_source': 'document.body','proxy': 'http://proxy_ip:proxy_port'}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读