|
#! /usr/bin/env python3
# lucky.py - Open several Baidu search results.
import requests, sys, webbrowser, bs4
print('Baiduing...') # display text while downloading the Baidu page
res = requests.get('http://www.baidu.com/s?wd='+ ' '.join(sys.argv[1:]))
res.raise_for_status()
# Retrieve top search result links.
soup = bs4.BeautifulSoup(res.text)
# Open a browser tab for each result.
linkElems = soup.select('.t a')
numOpen = min(5, len(linkElems))
for i in range(numOpen):
webbrowser.open(linkElems[i].get('href')) |
|