【问题标题】:Proxy servers with Scrapy-Splash带有 Scrapy-Splash 的代理服务器
【发布时间】:2017-03-29 10:01:55
【问题描述】:

我正在尝试让代理服务器在我的本地启动实例上工作。我已经阅读了几份文件,但没有找到任何可行的例子。我注意到这个https://github.com/scrapy-plugins/scrapy-splash/issues/107 是原因。我不再获得该回溯,但仍然无法将 Splash 与代理一起使用。下面的新错误消息。如果有人可以帮助我解决这个问题,请提前感谢。我的任何请求都没有通过 Splash。

  def parse_json(self, response):
    json_data = response.body
    load = json.loads(json_data.decode('utf-8'))
    dump = json.dumps(load,sort_keys=True,indent=2)
    LUA_SOURCE = """
    function main(splash)
        local host = "proxy.crawlera.com"
        local port = 8010
        local user = "APIKEY"
        local password = ""
        local session_header = "X-Crawlera-Session"
        local session_id = "create"

        splash:on_request(function (request)
            request:set_header("X-Crawlera-UA", "desktop")
            request:set_header(session_header, session_id)
            request:set_proxy{host, port, username=user, password=password}
        end)

        splash:on_response_headers(function (response)
            if response.headers[session_header] ~= nil then
                session_id = response.headers[session_header]
            end
        end)

        splash:go(splash.args.url)
        return splash:html()
    end
    """
    for link in load['d']['blogtopics']:
        link = link['Uri']
        yield SplashRequest(link, self.parse_blog, endpoint='execute',  args={'wait': 3, 'lua_source': LUA_SOURCE})


2017-03-29 09:26:37 [scrapy.core.engine] DEBUG: Crawled (503) <GET http://community.martindale.com/legal-blogs/Practice_Areas/b/corporate__securities_law/archive/2011/08/11/sec-adopts-new-rules-replacing-credit-ratings-as-a-criterion-for-the-use-of-short-form-shelf-registration.aspx via http://localhost:8050/execute> (referer: None)

【问题讨论】:

  • 看起来像这个未解决的问题:github.com/scrapy-plugins/scrapy-splash/issues/107
  • 你说得对,只是在我的支持票上确认了一个错误。希望它很快得到修复。我不想放弃飞溅。
  • @eusid 我认为 crawlera 需要更多自定义启动代码 - 你可以在这里查看示例 doc.scrapinghub.com/crawlera.html#using-crawlera-with-splash 吗?
  • 我从那个解决方案开始,但为了简单起见,将其缩小到这个范围。你知道需要什么吗?设置标题?
  • 使用具有相同结果的确切代码。有没有人有这个工作? 503 错误。我真的很想使用 splash 但考虑放弃只使用常规的 webkit。必须有人知道如何完成这项工作。

标签: python web-scraping scrapy scrapy-splash splash-js-render


【解决方案1】:

问题似乎是由 Crawlera 中间件引起的。 SplashRequest 没有任何处理。它尝试通过代理到我的本地主机。

【讨论】:

  • 还要添加注释,代理在主请求上工作,但在许多浏览器子请求上都失败了,因为 crawlera 是基于请求的,每个请求实际上是很多请求。
猜你喜欢
  • 2017-09-24
  • 1970-01-01
  • 2018-02-12
  • 2016-09-03
  • 2018-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-01
相关资源
最近更新 更多