Downloading a picture via urllib and python

后端 未结 18 1563
离开以前
离开以前 2020-11-22 10:35

So I\'m trying to make a Python script that downloads webcomics and puts them in a folder on my desktop. I\'ve found a few similar programs on here that do something simila

18条回答
  •  [愿得一人]
    2020-11-22 11:08

    If you know that the files are located in the same directory dir of the website site and have the following format: filename_01.jpg, ..., filename_10.jpg then download all of them:

    import requests
    
    for x in range(1, 10):
        str1 = 'filename_%2.2d.jpg' % (x)
        str2 = 'http://site/dir/filename_%2.2d.jpg' % (x)
    
        f = open(str1, 'wb')
        f.write(requests.get(str2).content)
        f.close()
    

提交回复
热议问题