在Python 3中使用Google的正确方法是什么?我已尝试将requests
和urllib
用于Google页面。当我只是res = requests.get("https://www.google.com/#q=" + query)
时没有使用与我在Safari中检查Google页面时相同的HTML。 urllib
也是如此。当我使用Bing时会发生类似的事情。我熟悉AJAX
。但是,现在似乎已经折旧了。
答案 0 :(得分:0)
在python中,如果您没有手动在http请求中指定用户代理标头,默认情况下python会为您添加,Google可以检测到它并且可能被禁止。
如果可以提供帮助,请尝试以下操作。
import urllib
yourUrl = "post it here"
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
req = urllib.request.Request(yourUrl, headers = headers)
page = urllib.request.urlopen(req)