如何解决Scrapy+Splash 返回错误的标题
在 Scrapy 中使用 Splash 时,标头从 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_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
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。