Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import urllib.request, urllib.parse, urllib.error
- import sys
- import os
- def download_media(url):
- resp = requests.get(url)
- if resp.status_code == 200:
- soup = BeautifulSoup(resp.text, 'html.parser')
- tags_with_media = soup.find_all('a',class_='post__image-link')
- for tag in tags_with_media:
- file_link = 'https://2ch.hk' + tag['href']
- destination = './downloads/' + file_link.rsplit('/',1)[1]
- print('start: ', file_link)
- urllib.request.urlretrieve(file_link, destination)
- print('end: ', file_link)
- else:
- print('connection error')
- if __name__ == '__main__':
- try:
- os.mkdir('downloads')
- print('the download folder was created')
- except:
- print('the download folder is used')
- URL = str(sys.argv[1])
- download_media(URL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement