我需要在python的帮助下获得前15页的谷歌搜索结果。我试着用这个答案Extract Google Search Results。但我没有得到先前的结果。我需要150个搜索结果,与python的原始链接。如果有人知道,给我这个解决方案。提前致谢。Python脚本获取150 Google搜索结果
-2
A
回答
0
我得到了150个的搜索结果是这样的:
import sys # Used to add the BeautifulSoup folder the import path
import urllib2 # Used to read the html document
if __name__ == "__main__":
### Import Beautiful Soup
### Here, I have the BeautifulSoup folder in the level of this Python script
### So I need to tell Python where to look.
sys.path.append("./BeautifulSoup")
from BeautifulSoup import BeautifulSoup
### Create opener with Google-friendly user agent
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
### Open page & generate soup
### the "start" variable will be used to iterate through 10 pages.
for start in range(0,15):
url = "http://www.google.com/search?q=site:stackoverflow.com&start=" + str(start*10)
page = opener.open(url)
soup = BeautifulSoup(page)
### Parse and find
### Looks like google contains URLs in <cite> tags.
### So for each cite tag on each page (10), print its contents (url)
for cite in soup.findAll('cite'):
print cite.text
你只需要之前安装BeautifulSoup
:pip install BeautifulSoup
。
的代码你提到的链接来了:使用Python wrapper回购Extract Google Search Results
+0
是的。它正在工作。谢谢。但手动检查时略有不同。但我不知道这个原因。? – Ganeshgm7
1
或者,你可以使用SERP API
的说明相当简单:
pip install google-search-results
和用法是:
from lib.google_search_results import GoogleSearchResults
query = GoogleSearchResults({"q": "coffee"})
html_results = query.get_html()
更高级的用途在SERP API Github上。
相关问题
- 1. Google搜索Python脚本
- 2. 获取Google讨论搜索结果
- 3. 使用JSoup获取Google搜索结果
- 4. 使用Rails获取Google搜索结果
- 5. 提取Google搜索结果
- 6. Python。从Google搜索结果中仅获取href链接内容
- 7. 从Google搜索结果网址获取搜索查询
- 8. Google Maps API Places搜索获取搜索结果数量
- 9. 从Bing搜索获取搜索结果
- 10. 如何执行Google搜索并获取文本结果?
- 11. google api搜索结果
- 12. 访问Google搜索结果
- 13. “Google搜索图片”的Python脚本
- 14. 提取Google搜索结果重定向
- 15. 更新Google搜索结果文本
- 16. 在PHP中搜索Google搜索结果
- 17. 解析Google搜索结果的BeautifulSoup脚本停止工作
- 18. Google Apps脚本Gmail明星搜索结果
- 19. Google搜索结果限制
- 20. Google地方搜索结果
- 21. 在Google中搜索结果
- 22. 优化Google搜索结果
- 23. Google搜索结果页面
- 24. 如何使用Python 3获得Google搜索结果?
- 25. 使用Python(或R)提取Google学术搜索结果
- 26. 如何在Google搜索结果页中提取搜索结果的总量
- 27. 获取特定搜索字符串的Google搜索结果网址
- 28. 用Python抓取aspx机械化 - 获取搜索结果
- 29. Google搜索结果TXT文件
- 30. 获取Google搜索结果和清除HTML标记的建议
这种问题真的是史诗般的。 Ganeshgm7,请问你可以给你的问题添加一些你尝试的例子吗?那太好了。 – Thomas