Guest User

4chan-get

a guest
Nov 20th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import argparse, bs4, os, urllib.request
  4.  
  5. parser = argparse.ArgumentParser()
  6. parser.add_argument("url", help="Link to 4chan thread")
  7. parser.add_argument("-d",  help="Directory to download to")
  8. args = parser.parse_args()
  9.  
  10. if args.d:
  11.     if not os.path.exists(args.d):
  12.         os.makedirs(args.d)
  13.     os.chdir(args.d)
  14.  
  15. soup = bs4.BeautifulSoup(urllib.request.urlopen(args.url))
  16.  
  17. for link in soup.find_all("a", class_="fileThumb"):
  18.     image = "https:" + link.get("href")
  19.     filename = image.rsplit("/", 1)[1]
  20.     if not os.path.exists(filename):
  21.         urllib.request.urlretrieve(image, filename)
Advertisement
Add Comment
Please, Sign In to add comment