Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import argparse, bs4, os, urllib.request
- parser = argparse.ArgumentParser()
- parser.add_argument("url", help="Link to 4chan thread")
- parser.add_argument("-d", help="Directory to download to")
- args = parser.parse_args()
- if args.d:
- if not os.path.exists(args.d):
- os.makedirs(args.d)
- os.chdir(args.d)
- soup = bs4.BeautifulSoup(urllib.request.urlopen(args.url))
- for link in soup.find_all("a", class_="fileThumb"):
- image = "https:" + link.get("href")
- filename = image.rsplit("/", 1)[1]
- if not os.path.exists(filename):
- urllib.request.urlretrieve(image, filename)
Advertisement
Add Comment
Please, Sign In to add comment