【发布时间】:2019-12-26 16:44:05
【问题描述】:
我正在尝试实现简单的刮刀,但是遇到了一些问题。不知何故,网站拒绝来自无头 chrome 的连接。这是第一个也是唯一的请求,没有任何 javascript 执行。来自普通 chrome 的请求运行良好,因此它绝对不是被禁止的 ip。这里有什么问题?他们是如何检测到它的?
我正在运行普通的 headless chrome,然后我替换了用户代理,仅此而已。
.\chrome.exe --headless --remote-debugging-port=9222
General:
Request URL: https://www.adidas.de/
Request Method: GET
Status Code: 403
Remote Address: 23.210.248.137:443
Referrer Policy: no-referrer-when-downgrade
Response Headers:
cache-control: max-age=0, no-cache, no-store
content-length: 1952
content-type: text/html
date: Thu, 26 Dec 2019 16:16:49 GMT
expires: Thu, 26 Dec 2019 16:16:49 GMT
pragma: no-cache
status: 403
Request Headers:
:authority: www.adidas.de
:method: GET
:path: /
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br
cache-control: max-age=0
sec-fetch-mode: navigate
sec-fetch-site: none
sec-fetch-user: ?1
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36
【问题讨论】:
-
要解决您的具体问题,您需要获取 Telerik Fiddler 或 Wireshark 并观察 chrome 与网站的交互。您的工作将是使用无头浏览器模拟这些交互。特别要注意 User-Agent 信息。
-
能否分享来自正常模式下的 Chrome 和无头 Chrome 的请求转储?有什么区别吗?还要注意重定向 30 倍(在 Chrome 开发人员工具的网络选项卡上勾选“保留日志”复选框)。
-
@RobertHarvey 我不知道是什么原因导致的,但 Fiddler 不允许将请求传递给 chrome,而且它仅在无头模式下发生。但是在正常模式下,它是第一个请求,在 http CONNECT 数据包之后,我认为它在无头模式下必须相同。
-
@omegastripes 好的,我很确定没有区别,但 headless 没有发送 Accept-Language,这是个问题。
-
请将其作为答案发布,它可能对其他人有所帮助。
标签: google-chrome http web-scraping https google-chrome-headless