avatar

目錄
【Python 爬蟲】抓取 Google 搜尋結果的連結

記錄一下批量抓取 Google 搜尋結果裡的連結的方法。


如果還沒有安裝以下,要先下載安裝:

cmd
pip install beautifulsoup4
pip install google

Code

python
from googlesearch import search

query = "cambridge"

for j in search(query, stop=5, pause=2.0):
print(j)

Result

result

解釋

  • query : keywords for searching
  • stop : Last result to retrieve. Use None to keep searching forever.
  • pause : Lapse to wait between HTTP requests. Lapse too short may cause Google to block your IP. Keeping significant lapse will make your program slow but its safe and better option.

References


如果您喜歡我的文章,歡迎幫我在下面按5下讚!感謝您的鼓勵和支持!

文章作者: ouoholly
文章鏈接: https://ouoholly.github.io/post/python-web-crawl-google-search-result-urls/
版權聲明: 本博客所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。歡迎「部份引用」與介紹(如要全文轉貼請先留言詢問),轉載引用請註明來源 ouoholly 的倉庫,謝謝!

評論