我正在使用以下基础架构来抓取网站:
Scrapy <--> Splash <--> Scrapoxy <--> web site
我正在通过Splash 执行端点发出请求,使用如下 Lua 脚本:
function main(splash)
local host = "..."
local port = "..."
local username = "..."
local password = "..."
splash:on_request(function (request)
request:set_proxy{host, port, username=username, password=password}
end)
splash:go(splash.args.url)
return splash:html()
end
我想检测禁令并删除被禁止的代理。根据Scrapoxy 文档:
Scrapoxy 在响应中添加一个 HTTP 标头
x-cache-proxyname
但我没有在response.headers
. 唯一的标题是:
{b'Content-Type': b'text/html; charset=utf-8',
b'Date': b'Wed, 18 Apr 2018 19:02:21 GMT',
b'Server': b'TwistedWeb/16.1.1'}
我究竟做错了什么?我应该在 Lua 脚本中添加一些内容以正确返回标头吗?
更新:实际上,这似乎不是飞溅问题。x-cache-proxyname
即使通过 HTTPie 使用Scrapoxy 也不会返回。
http -v --proxy=https:http://<user>:<password>@<scrapoxy-server>:8888 https://<site>
GET / HTTP/1.1
User-Agent: HTTPie/0.9.9
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Host: <site>
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 28 Jun 2018 08:14:26 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Set-Cookie: <...>
X-Powered-By: Express
ETag: W/"5a31b-faPJ7bjKH24S/3EvHU/8IoJHyxw"
Vary: Cookie, User-Agent
Content-Security-Policy: default-src https:; child-src https:; connect-src https: wss:; form-action https:; frame-ancestors https: http://webvisor.com; media-src https:; object-src https:; img-src https: data: blob:; script-src https: data: 'unsafe-inline' 'unsafe-eval'; style-src https: 'unsafe-inline'; font-src https: data:; report-uri /ajax/csp-report/
Content-Encoding: gzip