No schema supplied and other errors with using requests.get()

后端 未结 5 1123
情深已故
情深已故 2020-12-09 10:05

I\'m learning Python by following Automate the Boring Stuff. This program is supposed to go to http://xkcd.com/ and download all the images for offline viewing.

I\'

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 10:33

    Actually this is not a bigdeal.you can see the comicUrl somewhat like this //imgs.xkcd.com/comics/acceptable_risk.png

    The only thing you need to add is http: , remember it is http: and not http:// as some folks said earlier because already the url contatin double slashes. so please change the code to

    res = requests.get('http:' + comicElem[0].get('src'))
    

    or

    comicUrl = 'http:' + comicElem[0].get('src')
    
    res = requests.get(comicUrl)
    

    Happy coding

提交回复
热议问题