Download files from a list if not already downloaded

后端 未结 3 464
离开以前
离开以前 2020-12-31 15:02

I can do this in c#, and the code is pretty long.

Would be cool if someone can show me how this would be done via python.

Pseudo code is:

u         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-31 15:41

    It's less code in Python, you could use something like this:

    import urllib2
    improt os
    
    url="http://.../"
    # Translate url into a filename
    filename = url.split('/')[-1]
    
    if not os.path.exists(filename)
      outfile = open(filename, "w")
      outfile.write(urllib2.urlopen(url).read())
      outfile.close()
    

提交回复
热议问题