2014-01-12 18 views
0

如果我們鍵入谷歌搜索框搜索詞索引的網頁提取號碼,它返回類似:的Python:在谷歌

About x results (y seconds) 

我怎樣才能提取使用Python 3搜索結果這一行? 感謝您的幫助。

回答

2

使用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)' 
+0

我安裝了,但仍然得到錯誤 – TJ1

+0

是的,現在的工作真的很感謝你需要更新與這些進口你的答案它做的,所以我能接受它? – TJ1

+0

非常感謝,作品非常漂亮。 – TJ1