【问题标题】:Scrapy+Splash returning wrong headersScrapy+Splash 返回错误的标题
【发布时间】:2021-07-11 07:38:40
【问题描述】:

将 Splash 与 Scrapy 一起使用时,标头从 Splash 服务器而不是 Splash 呈现的网站返回。

response.headers 返回:

{b'Server': [b'TwistedWeb/19.7.0'], b'Date': [b'Sun, 11 Jul 2021 07:31:32 GMT'], b'Content-Type': [b'text/html; charset=utf-8']}

我正在尝试获取实际网站的标题:

Connection: Keep-Alive
Content-Length: 5
Content-Type: text/html
Date: Sun, 11 Jul 2021 07:05:49 GMT
Keep-Alive: timeout=5, max=100
Server: Apache
X-Cache: HIT

如何获取网站的标头而不是 Splash 服务器?

【问题讨论】:

    标签: scrapy scrapy-splash


    【解决方案1】:

    我得到了它的工作:

    splash_lua_script = """
    function main(splash, args)
        assert(splash:go(args.url))
        assert(splash:wait(0.5))
    
        local entries = splash:history()
        local last_response = entries[#entries].response
    
        return {
            html = splash:html(),
            headers = last_response.headers
        }
    end
    """
    

    然后使用 Scrapy 将其提交给 response.headers

    【讨论】:

      猜你喜欢
      • 2019-06-26
      • 2017-05-27
      • 1970-01-01
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      • 2017-12-24
      • 1970-01-01
      相关资源
      最近更新 更多