Module 2 Programs
Module 2 Programs
python3
# mapIt.py - Launches a map in the browser using an
address from the # command line or clipboard.
import webbrowser, sys, pyperclip
if len(sys.argv)>1:
#Get address from command line
#print(sys.argv[1:])
address=' '.join(sys.argv[1: ])
print(address)
else:
#Get address from clipboard
address=pyperclip.paste()
webbrowser.open('https://www.google.com/maps/place/'+
address)
2nd program
import requests, sys, webbrowser, bs4
print('Googling...') # display text while downloading the
Google page
res = requests.get('http://google.com/' + '
'.join(sys.argv[1:]))
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[i].get('href'))