我需要在python的幫助下獲得前15頁的谷歌搜索結果。我試着用這個答案Extract Google Search Results。但我沒有得到先前的結果。我需要150個搜索結果,與python的原始鏈接。如果有人知道,給我這個解決方案。提前致謝。Python腳本獲取150 Google搜索結果
-2
A
回答
0
我得到了150個的搜索結果是這樣的:
import sys # Used to add the BeautifulSoup folder the import path
import urllib2 # Used to read the html document
if __name__ == "__main__":
### Import Beautiful Soup
### Here, I have the BeautifulSoup folder in the level of this Python script
### So I need to tell Python where to look.
sys.path.append("./BeautifulSoup")
from BeautifulSoup import BeautifulSoup
### Create opener with Google-friendly user agent
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
### Open page & generate soup
### the "start" variable will be used to iterate through 10 pages.
for start in range(0,15):
url = "http://www.google.com/search?q=site:stackoverflow.com&start=" + str(start*10)
page = opener.open(url)
soup = BeautifulSoup(page)
### Parse and find
### Looks like google contains URLs in <cite> tags.
### So for each cite tag on each page (10), print its contents (url)
for cite in soup.findAll('cite'):
print cite.text
你只需要之前安裝BeautifulSoup
:pip install BeautifulSoup
。
的代碼你提到的鏈接來了:使用Python wrapper回購Extract Google Search Results
+0
是的。它正在工作。謝謝。但手動檢查時略有不同。但我不知道這個原因。? – Ganeshgm7
1
或者,你可以使用SERP API
的說明相當簡單:
pip install google-search-results
和用法是:
from lib.google_search_results import GoogleSearchResults
query = GoogleSearchResults({"q": "coffee"})
html_results = query.get_html()
更高級的用途在SERP API Github上。
相關問題
- 1. Google搜索Python腳本
- 2. 提取Google搜索結果
- 3. Python。從Google搜索結果中僅獲取href鏈接內容
- 4. Google Maps API Places搜索獲取搜索結果數量
- 5. 從Google搜索結果網址獲取搜索查詢
- 6. 訪問Google搜索結果
- 7. 提取Google搜索結果重定向
- 8. 更新Google搜索結果文本
- 9. 在PHP中搜索Google搜索結果
- 10. Google Apps腳本Gmail明星搜索結果
- 11. 解析Google搜索結果的BeautifulSoup腳本停止工作
- 12. Google搜索結果頁面
- 13. 如何使用Python 3獲得Google搜索結果?
- 14. Google搜索結果TXT文件
- 15. 無法使用JSON獲取Google自定義搜索結果
- 16. 在JavaScript中使用JSON從Google搜索獲取結果Ajax API
- 17. 如何從應用程序後端獲取Google搜索結果?
- 18. 以編程方式獲取Google搜索結果
- 19. Google Search API - 獲取「常規」谷歌搜索結果
- 20. 獲取Google搜索結果和清除HTML標記的建議
- 21. 如何使用jquery獲取Google搜索API結果href值
- 22. 如何獲取Google搜索的最佳結果?
- 23. Google Ajax搜索結果與「普通」Google搜索結果有什麼不同?
- 24. 使用ImportXML導入Google搜索結果
- 25. Google應用索引ios搜索結果
- 26. 從控制器獲取搜索結果
- 27. 獲取谷歌搜索結果數
- 28. 獲取谷歌搜索結果在c#
- 29. 獲取谷歌和yandex搜索結果
- 30. 從php獲取搜索結果在php
這種問題真的是史詩般的。 Ganeshgm7,請問你可以給你的問題添加一些你嘗試的例子嗎?那太好了。 – Thomas