【问题标题】:Return the number of results for google search返回 google 搜索的结果数
【发布时间】:2015-11-04 13:48:12
【问题描述】:

有没有一种快速的方法可以在 Google 中搜索一对字符串(例如 'married life' 和 'happy living' )并返回结果数量?我可以手动做到这一点,但我有大量的单词,很想知道是否有更好的方法。

【问题讨论】:

  • “google python number of results”的结果很多
  • @vaultah 但是你怎么知道有多少,使用 Python?
  • 其中一些结果:123@jonrsharpe
  • @vaultah ...那是个笑话!
  • 在我的 Python 安装中,有一个文件“Google.py”(我必须承认,我正在使用 Python 3.4)。如果您也有这个库,我建议您尝试使用它并在您的网络浏览器中解析结果。 (如果你没有这个库,不要杀我:-))

标签: python python-2.7


【解决方案1】:

您可以使用以下代码:

import requests
from bs4 import BeautifulSoup

search = "django framework"

r = requests.get("https://www.google.com/search", params={'q':search})

soup = BeautifulSoup(r.text, "lxml")
res = soup.find("div", {"id": "resultStats"})
print res.text

输出

About 10,400,000 results

附加:如果您想要确切的数字,则可以使用以下行:

print int(res.text.replace(",", "").split()[1])

输出

10400000

【讨论】:

  • 问题是谷歌在 X 数量的请求后禁止你。有没有办法做到这一点而不会被禁止
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-21
  • 2016-08-07
  • 1970-01-01
  • 2013-09-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多