我一直在尝试从谷歌搜索中提取数据,但我无法绕过“在继续使用谷歌搜索之前”同意书。
我试图找到一种解决方法,并看到其他人建议使用 argumentCONSENT=PENDING+999或类似于CONSENT = YES+HU.hu+V10+B+256get 请求的内容。不幸的是,我无法使前一种工作,在后一种情况下,我不完全确定最后三个元素应该替换为什么。
我在下面附上来自此处的示例代码。
import requests
import bs4
headers = {'User-Agent':'Chrome 83 (Toshiba; Intel(R) Core(TM) i3-2367M CPU @ 1.40 GHz)'\
'Windows 7 Home Premium',
'Accept':'text/html,application/xhtml+xml,application/xml;'\
'q=0.9,image/webp,*/*;q=0.8',
#'cookie': 'CONSENT = YES+HU.hu+V10+B+256' # what are the last three elements?
'cookie':'CONSENT=PENDING+999'
}
text= "geeksforgeeks"
url = 'https://google.com/search?q=' + text
request_result=requests.get( url , headers = headers) # here's where the trouble happens
soup = bs4.BeautifulSoup(request_result.text, "html.parser")
print(soup) # not what one would expect
heading_object=soup.find_all( …Run Code Online (Sandbox Code Playgroud)