【发布时间】:2021-04-21 15:16:54
【问题描述】:
在抓取重定向 google url 后,我遇到了 google 协议页面 cookie 的问题。
我正在尝试从 Google 新闻 uri 上的不同页面抓取,但是当我运行此代码时:
req = requests.get(url,headers=headers)
with "headers" = {'User-Agent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/534.1 (KHTML, like Gecko) Chrome/6.0.422.0 Safari/534.1', 'Upgrade-Insecure-Requests': '1', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'DNT': '1', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'it-IT'}
and for example URL = https://news.google.com/./articles/CAIiEMb3PYSjFFVbudiidQPL79QqGQgEKhAIACoHCAow-ImTCzDRqagDMKiIvgY?hl=it&gl=IT&ceid=IT%3Ait
the "request.content" is the HTMLs code of agreement cookies page by Google.
我也尝试将重定向链接转换为普通链接,但响应为我提供了指向this的重定向链接
我有与此问题相关的相同问题 (How can I bypass a cookie agreement page while web scraping using Python?)。
无论如何,其中提出的解决方案仅适用于特定站点。
注意:整个代码直到几周前才有效。
【问题讨论】:
标签: python web-scraping cookies