Python:提取Goog中索引页的数量

2024-04-20 05:26:14 发布

您现在位置:Python中文网/ 问答频道 /正文

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

About x results (y seconds)

如何使用python3从搜索结果中提取这一行? 谢谢你的帮助。在


Tags: 内容googleresultspython3aboutseconds
1条回答
网友
1楼 · 发布于 2024-04-20 05:26:14

使用^{}(和^{}):

>>> 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)'

相关问题 更多 >