I am learning Python following the principle of Automation the Boring Stuff. It is assumed that this program will go to http://xkcd.com/ and download all the images for viewing offline.
I am on version 2.7 and Mac.
For some reason, I get error messages like "No schema specified" and errors using request.get () itself.
Here is my code:
# Saves the XKCD comic page for offline read import requests, os, bs4, shutil url = 'http://xkcd.com/' if os.path.isdir('xkcd') == True:
Here are the errors:
Traceback (most recent call last): File "/Users/XKCD.py", line 30, in <module> res = requests.get(comicUrl) # Get the image. Getting something will always use requests.get() File "/Library/Python/2.7/site-packages/requests/api.py", line 69, in get return request('get', url, params=params, **kwargs) File "/Library/Python/2.7/site-packages/requests/api.py", line 50, in request response = session.request(method=method, url=url, **kwargs) File "/Library/Python/2.7/site-packages/requests/sessions.py", line 451, in request prep = self.prepare_request(req) File "/Library/Python/2.7/site-packages/requests/sessions.py", line 382, in prepare_request hooks=merge_hooks(request.hooks, self.hooks), File "/Library/Python/2.7/site-packages/requests/models.py", line 304, in prepare self.prepare_url(url, params) File "/Library/Python/2.7/site-packages/requests/models.py", line 362, in prepare_url to_native_string(url, 'utf8'))) requests.exceptions.MissingSchema: Invalid URL '//imgs.xkcd.com/comics/the_martian.png': No schema supplied. Perhaps you meant http:////imgs.xkcd.com/comics/the_martian.png?
The fact is that I read the section in the book about the program many times, read the Requests document, and also looked at other questions here. My syntax looks right.
Thank you for your help!
Edit:
This did not work:
comicUrl = ("http:"+comicElem[0].get('src'))
I thought adding http: before would get rid of the missing schema error.