Python:提取谷歌中索引页面的数量



如果我们在谷歌搜索框中输入一个搜索词,它会返回如下内容:

About x results (y seconds)

如何使用 Python 3 从搜索结果中提取此行?感谢您的帮助。

使用 lxml (和 cssselect

):
>>> import urllib.request
>>> import lxml.html
>>> html = .. urllib.request.urlopen .. http://www.google.com/search?q=python ..
           .read()
>>> root = lxml.html.fromstring(html)
>>> div, = root.cssselect('#resultStats')
>>> div.text_content().strip()
'About 46,600,000 results  (0.17 seconds)'

最新更新