LorenKPetrov

WallScraper

Dec 28th, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. from lxml import html
  2. from datetime import date
  3. import urllib
  4. import requests
  5. import time
  6. import os
  7.  
  8. # Variables #
  9. start = 0
  10.  
  11. # File Variables #
  12. filepre = "WG"
  13. filenum = 0
  14. filetime = time.strftime("%H.%M")
  15. filedate = [date.today().day,date.today().month,date.today().year]
  16. filediv = ["_","-"]
  17. filename = filepre+filediv[0]+str(filedate[0])+filediv[1]+str(filedate[1])+filediv[1]+str(filedate[2])+filediv[0]+str(filenum)
  18.  
  19. # Directory Variables #
  20. dir = "C:/wallpaper/"
  21.  
  22. os.system("cls")
  23. print "\n 4Chan IMG Thread Scraper"
  24. time.sleep(1)
  25. os.system("cls")
  26. print "\n What is the thread link?"
  27. post = raw_input(" > ")
  28.  
  29. os.system("cls")
  30. print "\n What would you like the folder to be called?"
  31. foldername = raw_input(" > ")
  32.  
  33. page = requests.get(post)
  34. tree = html.fromstring(page.text)
  35. link = tree.xpath('//a[@class="fileThumb"]/@href')
  36.  
  37. totalImgs = len(link)
  38.  
  39. os.chdir(dir)
  40. os.system("mkdir "+foldername)
  41.  
  42. savedir = dir+foldername+"/"
  43.  
  44. while start < totalImgs:
  45.    
  46.     os.system("cls")
  47.     print "\n Number:",str(start)
  48.     print " Total Images:",str(totalImgs)
  49.     print " Thread Link:",post
  50.     print " Image Link:","http:"+link[start]
  51.     print " Saving to:",foldername
  52.     print "\n"
  53.     filenum = filenum + 1
  54.     urllib.urlretrieve("http:"+link[start], savedir+filename+str(filenum)+".jpg")
  55.     start = start + 1
  56.    
  57. os.system("cls")
  58. print "\n Scrape completed!"
  59. time.sleep(2)
Advertisement
Add Comment
Please, Sign In to add comment