gpt4 book ai didi

python - 谷歌 http 请求被阻止

转载 作者:可可西里 更新时间:2023-11-01 17:17:34 28 4
gpt4 key购买 nike

我正在尝试使用 python 执行谷歌搜索。但显然google就是这样要求的。我正在使用请求模块并且已经尝试为用户代理设置 header 。

到目前为止,这是我的代码:

# -*- coding: utf-8 -*-
import requests
ua = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36'}

r = requests.get('http://google.com?q=how+old+is+selena+gomez', headers=ua)
content = r.content
counted = content.count('26')
print counted

但是当我查看返回的 HTML 时,我根本找不到答案。

有没有可能的解决方案?

最佳答案

But when I look at the returned HTML, I simply cannot find the answer.

这是因为您使用了错误的 url。

http://google.com?q=how+old+is+selena+gomez

会给你这个页面 enter image description here

你需要的网址是

https://www.google.com/search?q=how+old+is+selena+gomez

这会给你 enter image description here

关于python - 谷歌 http 请求被阻止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54671528/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com