diff options
author | mlot <petri-rush-curvy@duck.com> | 2025-06-06 13:40:57 -0400 |
---|---|---|
committer | mlot <petri-rush-curvy@duck.com> | 2025-06-06 13:40:57 -0400 |
commit | 75a42ec54dbf721caa659ddf02c1f46fc2cb4bef (patch) | |
tree | 84be794a2481e356a7784557a6f9fb6fbf29cfdd /Chapter11ProjectLucky.py |
Diffstat (limited to 'Chapter11ProjectLucky.py')
-rw-r--r-- | Chapter11ProjectLucky.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Chapter11ProjectLucky.py b/Chapter11ProjectLucky.py new file mode 100644 index 0000000..c77858f --- /dev/null +++ b/Chapter11ProjectLucky.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +#Chapter 11 Project +# lucky.py - Opens several Google search results + +import requests +import sys +import webbrowser +import bs4 + +print('Googling...') #Display message while retrieving the Google page + +res = requests.get('http://google.com/search?q=' + ' '.join(sys.argv[1:])) +res.raise_for_status() + +soup = bs4.BeautifulSoup(res.text) +linkElems = soup.select('.r a') + +numOpen = min(5, len(linkElems)) +for i in range(numOpen): + webbrowser.open('htpp://google.com' + linkElems[i].get('href')) |