Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python进行web抓取时绕过cookie协议页_Python_Web Scraping_Cookies - Fatal编程技术网

使用Python进行web抓取时绕过cookie协议页

使用Python进行web抓取时绕过cookie协议页,python,web-scraping,cookies,Python,Web Scraping,Cookies,在抓取重定向谷歌url后,我面临谷歌协议页面cookies的问题 我试图从谷歌新闻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) Chr

在抓取重定向谷歌url后,我面临谷歌协议页面cookies的问题

我试图从谷歌新闻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.
我还尝试将重定向链接转换为正常链接,但响应将重定向链接提供给我

关于这个问题,我也有同样的问题()

无论如何,本文中提出的解决方案仅适用于特定站点


注意:整个代码直到几周前才开始工作。

我通过添加行解决了这个问题

“Cookie”:“同意=是+cb.20210418-17-p0.it+FX+917;”

到请求头

虽然请求返回的页面仍然是Google页面,但该页面包含指向请求发起站点的链接

所以,一旦我得到了页面,我就做了更多的刮削,这样我就可以得到链接并开始我想要的请求