Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, requests, bs4
- os.makedirs('2ch_pepe', exist_ok=True)
- dvach_url = 'https://2ch.hk'
- res = requests.get(f'{dvach_url}/b/res/223080100.html')
- res.raise_for_status()
- soup = bs4.BeautifulSoup(res.text, features='html.parser')
- image_list = soup.select('img')
- new_ones = 0
- for image in image_list:
- image_src = image.get("src")
- print(f'Загружается изображение {os.path.basename(image_src)}...')
- res = requests.get(f'{dvach_url}{image_src}')
- res.raise_for_status()
- if os.path.isfile(os.path.join('2ch_pepe', os.path.basename(image_src))):
- print('Изображение уже существует, пропускаем.')
- continue
- with open(os.path.join('2ch_pepe', os.path.basename(image_src)), 'wb') as f:
- new_ones += 1
- for chunk in res.iter_content(10000):
- f.write(chunk)
- print(f'Готово. Было скачано {new_ones} Pepe.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement