willsonlincake 发表于 2022-4-26 20:22:47

谷歌随机搜索的Python实现

https://github.com/sebanti10/im-feeling-lucky-search/blob/master/lucky.py

willsonlincake 发表于 2022-4-26 20:22:56

#! python3
# lucky.py - Opens several Google search results.

import requests, sys, webbrowser, bs4


print('Googling...') # display text while downloading the Google page
res = requests.get('http://google.com/search?q=' + ' '.join(sys.argv))
res.raise_for_status()

#Retrieve top search result links
soup=bs4.BeautifulSoup(res.text, features="html.parser")
linkElems = soup.select('div#main > div > div > div > a')
numOpen = min(5, len(linkElems))
for i in range(numOpen):
    webbrowser.open('http://google.com' + linkElems.get('href'))

willsonlincake 发表于 2022-4-26 20:26:03

也就是随机搜索一个词汇
页: [1]
查看完整版本: 谷歌随机搜索的Python实现