将 Google 搜索返回到 Python [英] Returning Google Search To Python
本文介绍了将 Google 搜索返回到 Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从 Google 搜索中获取前 20 个结果.当我使用 urllib2.urlopen()
时,它给了我一个错误并说我被禁止了.我听说这与伪造用户代理字符串有关,但我几乎没有 urllib2 经验,如果有人能提供帮助,我将不胜感激.
I am trying to get the first 20 results from a Google search.
When I use urllib2.urlopen()
it gives me an error and says I am forbidden.
I heard that it has something to do with faking you user agent string, but i have next to no urllib2 experience and would be very grateful if anyone could help.
谢谢,乔达梅利奥
推荐答案
您可能应该只使用一个可以完成所有繁重工作的库.
You should probably just use a library that does all the hard work.
xGoogle 使您能够在列表中获取搜索结果
xGoogle enables you to get the search results in a list
从例子中,
from xgoogle.search import GoogleSearch
gs = GoogleSearch("quick and dirty")
gs.results_per_page = 50
results = gs.get_results()
这篇关于将 Google 搜索返回到 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文