Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import argparse, bs4, os, re, requests
- parser = argparse.ArgumentParser()
- parser.add_argument("url", help="Link to 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)
- spoof = {"user-agent" : "Mozilla/5.0 (X11; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0"}
- html = requests.get(args.url, headers=spoof).text
- soup = bs4.BeautifulSoup(html, "html.parser")
- for thumb in soup.find_all("a", href=re.compile("/photo/[0-9][0-9][0-9]")):
- url = "http://imagefap.com" + thumb.get("href")
- html2 = requests.get(url, headers=spoof).text
- soup2 = bs4.BeautifulSoup(html2, "html.parser")
- for image in soup2.find_all("img", src=re.compile("imagefapusercontent")):
- image_link = image.get("src")
- image_filename = image_link.split("/").pop()
- while os.path.exists(image_filename):
- image_filename = "_" + image_filename
- image_data = requests.get(image_link, headers=spoof)
- image_file = open(image_filename, "wb")
- image_file.write(image_data.content)
- image_file.close()
Add Comment
Please, Sign In to add comment