I am using the os module to issue a wget request through python. It looks something like this:
os.system("wget 'http://superawesomeurl.com'")
If I issue the wget request straight from terminal, it works, but I have two problems:
- When I build this in sublime, it give me the error:
sh: wget: command not found
- When I enter this into a python shell command line it sends the request but comes back bad:
400 bad request
I noticed that other people don't use the quotes around the url, but in terminal this is the only way it works. I am using python 2.7.8 and running Yosemite.
Your code should work if wget is on your PYTHONPATH.
But seriously, do not use wget in Python!
Better use a Python-native function like urlopen: https://docs.python.org/2/library/urllib2.html#urllib2.urlopen It's as simple as this:
Now
response
contains the whole contents of the html page. You can also usereadlines()
if you wanted to iterate over it line by line. To save the html file to disk use: