fork download
  1. # your code goes hereimport sys
  2. import urllib.request
  3. import os.path
  4.  
  5.  
  6. def dload(url,a):
  7. req=urllib.request.Request(url)
  8. try:
  9. img=urllib.request.urlopen(req)
  10. localfile=open(os.path.basename(a),"wb")
  11. localfile.write(img.read())
  12. img.close()
  13. localfile.close()
  14. except urllib.error.URLError as e:
  15. print(a)
  16. print(e.reason)
  17.  
  18. f=open("urls.txt","r")
  19. a=0
  20. for line in f:
  21. a=a+1
  22. string=str(a)
  23. fname="pic"+string.zfill(3)+".jpg"
  24. dname=os.getcwd()
  25. fpath=os.path.join(dname,fname)
  26.  
  27. print("start "+fpath)
  28. print(os.path.isfile(a))
  29. if os.path.isfile(a)!= True :
  30. dload(line,fpath)
  31. print("end "+fpath)
  32.  
  33.  
Runtime error #stdin #stdout #stderr 0.3s 15216KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 18, in <module>
IOError: [Errno 2] No such file or directory: 'urls.txt'