fork download
  1. import os
  2.  
  3. import requests
  4. from lxml import html
  5.  
  6. IMG_HREF_XPATH = '//a[img[contains(@class, "img preview")]]'
  7. WEB_ROOT = 'https://2...content-available-to-author-only...h.hk'
  8.  
  9. thread_url = input('Введите ссылку на тред\n')
  10. requests_obj = requests.get(thread_url)
  11. thread_source = html.fromstring(requests_obj.text)
  12.  
  13. if not os.path.exists('media'):
  14. os.makedirs('media')
  15.  
  16. for elem in thread_source.xpath(IMG_HREF_XPATH):
  17.  
  18. media_name = elem.get('href').split('/')[-1]
  19. media_url = WEB_ROOT + elem.get('href')
  20. response = requests.get(media_url, stream=True)
  21.  
  22. with open('media/{}'.format(media_name), 'wb+') as file:
  23. for chunk in response:
  24. file.write(chunk)
  25.  
  26. print('Downloaded: {}'.format(media_url))
  27.  
Runtime error #stdin #stdout #stderr 0.04s 9296KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
ImportError: No module named 'requests'