Guest User

Untitled

a guest
Apr 23rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import argparse, bs4, os, re, requests
  4.  
  5. parser = argparse.ArgumentParser()
  6. parser.add_argument("url", help="Link to 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. spoof = {"user-agent" : "Mozilla/5.0 (X11; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0"}
  16.  
  17. html = requests.get(args.url, headers=spoof).text
  18. soup = bs4.BeautifulSoup(html, "html.parser")
  19.  
  20. for thumb in soup.find_all("a", href=re.compile("/photo/[0-9][0-9][0-9]")):
  21.    
  22.     url = "http://imagefap.com" + thumb.get("href")
  23.     html2 = requests.get(url, headers=spoof).text
  24.     soup2 = bs4.BeautifulSoup(html2, "html.parser")
  25.    
  26.     for image in soup2.find_all("img", src=re.compile("imagefapusercontent")):
  27.  
  28.         image_link = image.get("src")
  29.         image_filename = image_link.split("/").pop()
  30.  
  31.         while os.path.exists(image_filename):
  32.             image_filename = "_" + image_filename
  33.            
  34.         image_data = requests.get(image_link, headers=spoof)
  35.         image_file = open(image_filename, "wb")
  36.         image_file.write(image_data.content)
  37.         image_file.close()
Add Comment
Please, Sign In to add comment