我希望以儘可能最快的方式僅返回特定關鍵字的谷歌搜索結果的數量,以避免(至少保留)使用第三方庫。我已經考慮過xgoogle。僅通過Python返回Google搜索結果的數量
回答
如果您搜索「汽車」之類的模糊內容,data
將如下所示。注意它不是很長;您只能獲得排名前幾位的點擊數,並可鏈接到「moreResultsUrl」。因此,進行此查詢的速度應該相當快,並在 data['cursor']['estimatedResultCount']
中查看估計的點擊次數。
{'cursor': {'currentPageIndex': 0,
'estimatedResultCount': '168000000',
'moreResultsUrl': 'http://www.google.com/search?oe=utf8&ie=utf8&source=uds&start=0&hl=en&q=cars',
'pages': [{'label': 1, 'start': '0'},
{'label': 2, 'start': '4'},
{'label': 3, 'start': '8'},
{'label': 4, 'start': '12'},
{'label': 5, 'start': '16'},
{'label': 6, 'start': '20'},
{'label': 7, 'start': '24'},
{'label': 8, 'start': '28'}]},
'results': [ <<list of 4 dicts>> ]}
您可以使用urllib下載網站,HTMLParser解析出 <div id="resultStats">....</div>
值。這裏有一個例子:
How can I use the python HTMLParser library to extract data from a specific div tag?
值得一提的是,當使用urllib時,你將不得不欺騙瀏覽器代理ID - 並且Google在自動查詢時皺眉了... – 2010-07-26 12:27:37
謝謝,這個答案也幫助我解決了其他困難。 – subiet 2010-07-28 04:10:24
- 1. Google Maps API本地搜索僅返回4個結果?
- 2. 爲什麼Google App Engine搜索僅返回「最佳」結果?
- 3. Excel的Google搜索結果數量
- 4. DataTable - 返回搜索結果
- 5. 如何通過python包查找Google搜索結果
- 6. 返回Google Search Appliance搜索結果中的元數據字段
- 7. 如何限制本C#程序中返回的Google搜索結果的數量?
- 8. 如何讓Google地圖搜索僅返回當前可見區域的結果?
- 9. Postgresql:返回搜索結果不在搜索結果
- 10. 通過JQuery Ajax和經典ASP返回搜索結果
- 11. Android GeoCoder:通過郵政編碼搜索返回意外結果
- 12. 如何通過Wikipedia API返回多個搜索結果?
- 13. 通過地圖列表搜索並返回多個結果
- 14. Google Custom Search僅返回「無結果」
- 15. Google自定義搜索僅限Python購物結果?
- 16. Python。從Google搜索結果中僅獲取href鏈接內容
- 17. Google Ajax搜索結果與「普通」Google搜索結果有什麼不同?
- 18. Google Maps API Places搜索獲取搜索結果數量
- 19. SearchListItems返回0結果,但SharePoint搜索返回5頁結果
- 20. 限制彈性搜索返回結果的數量
- 21. Sharepoint網絡服務搜索:返回的結果數量指定
- 22. 通過日誌文件Python自定義搜索不返回結果
- 23. Lucene搜索返回不同的結果
- 24. 0從NetSuite搜索返回的結果
- 25. Twitter的JSON搜索結果返回空
- 26. 雷達搜索Google Places API返回的結果太少
- 27. Google搜索返回頁面上的結果 - HTML
- 28. Facebook圖形API,僅返回經過驗證的帳戶的搜索結果
- 29. 數據庫搜索只返回1搜索結果
- 30. 過濾Google網站搜索結果
你的問題是什麼?你的代碼在哪裏? – SilentGhost 2010-07-26 10:56:36