fork download
  1. import urllib
  2. import urllib.request
  3. from bs4 import BeautifulSoup
  4. import os
  5. from string import ascii_lowercase
  6.  
  7. def make_soup(url):
  8. thepage = urllib.request.urlopen(url)
  9. soupdata = BeautifulSoup(thepage, "html.parser")
  10. return soupdata
  11.  
  12. def take_image(n):
  13. i=1
  14.  
  15. proxy = urllib.request.ProxyHandler({'http': '127.0.0.1'})
  16. opener = urllib.request.build_opener(proxy)
  17. urllib.request.install_opener(opener)
  18. urllib.request.urlopen(n)
  19.  
  20. soup1 = make_soup(n)
  21. for img in soup1.select('a[href] img'):
  22. temp = img.find_parent('a', href=True)['href']
  23.  
  24. try:
  25. if temp[:1] == "/":
  26. image = "https://,,,.hk" + temp
  27. else:
  28. image = temp
  29. print(image)
  30.  
  31. filename = str(i)
  32. i = i + 1
  33.  
  34. imagefile = open(filename + ".png", 'wb')
  35. imagefile.write(urllib.request.urlopen(image).read())
  36. imagefile.close()
  37. except:
  38. continue
  39.  
  40. with open('E:\Test.txt', 'r') as file:
  41. for line in file:
  42. n = line
  43. take_image(n)
Runtime error #stdin #stdout #stderr 0.09s 119424KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 40, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'E:\\Test.txt'