Reputation: 67
Every time I enter two addresses on the command line the addresses get squished together. Also I can't seem to get the page to download using requests. I'm sure it's a simple fix.
import webbrowser, sys, requests
address = ' '.join(sys.argv[1:])
SecondAddress = ' '.join(sys.argv[2:])
webbrowser.open("https://www.google.com/maps/place/"+address)
webbrowser.open("https://www.google.com/maps/dir/"+ address+"/"+SecondAddress)
RES = requests.get ('"https://www.google.com/maps/dir/"+address+"/"+SecondAddress')
output = open("directions.txt", 'wb')
for chunk in RES.iter_content(100000):
output.write(chunk)
output.close()
Upvotes: 0
Views: 55
Reputation: 105
Instead of writing this:
address = ' '.join(sys.argv[1:])
SecondAddress = ' '.join(sys.argv[2:])
Do this:
address = ' '.join(sys.argv[1])
SecondAddress = ' '.join(sys.argv[2])
Also you are not able to download the page using requests because you are not passing an url, you are passing this string: 'https://www.google.com/maps/dir/+address+/+SecondAddress'
Do this:
direction_url = "https://www.google.com/maps/dir/"+address+"/"+SecondAddress
RES = requests.get (direction_url)
Note: Pass both the addresses to the command line with '+' as a separator between each word like this:
python test.py airport+pune phoenix+mall+pune
Upvotes: 1