0% found this document useful (0 votes)
4 views2 pages

Module 2 Programs

The document contains two Python scripts. The first script, mapIt.py, opens a Google Maps page using an address provided via command line or clipboard. The second script retrieves and opens the top search results from Google based on a query provided in the command line.

Uploaded by

luckydollarxx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Module 2 Programs

The document contains two Python scripts. The first script, mapIt.py, opens a Google Maps page using an address provided via command line or clipboard. The second script retrieves and opens the top search results from Google based on a query provided in the command line.

Uploaded by

luckydollarxx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#!

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'))

You might also like