Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from lxml import html
- from datetime import date
- import urllib
- import requests
- import time
- import os
- # Variables #
- start = 0
- # File Variables #
- filepre = "WG"
- filenum = 0
- filetime = time.strftime("%H.%M")
- filedate = [date.today().day,date.today().month,date.today().year]
- filediv = ["_","-"]
- filename = filepre+filediv[0]+str(filedate[0])+filediv[1]+str(filedate[1])+filediv[1]+str(filedate[2])+filediv[0]+str(filenum)
- # Directory Variables #
- dir = "C:/wallpaper/"
- os.system("cls")
- print "\n 4Chan IMG Thread Scraper"
- time.sleep(1)
- os.system("cls")
- print "\n What is the thread link?"
- post = raw_input(" > ")
- os.system("cls")
- print "\n What would you like the folder to be called?"
- foldername = raw_input(" > ")
- page = requests.get(post)
- tree = html.fromstring(page.text)
- link = tree.xpath('//a[@class="fileThumb"]/@href')
- totalImgs = len(link)
- os.chdir(dir)
- os.system("mkdir "+foldername)
- savedir = dir+foldername+"/"
- while start < totalImgs:
- os.system("cls")
- print "\n Number:",str(start)
- print " Total Images:",str(totalImgs)
- print " Thread Link:",post
- print " Image Link:","http:"+link[start]
- print " Saving to:",foldername
- print "\n"
- filenum = filenum + 1
- urllib.urlretrieve("http:"+link[start], savedir+filename+str(filenum)+".jpg")
- start = start + 1
- os.system("cls")
- print "\n Scrape completed!"
- time.sleep(2)
Advertisement
Add Comment
Please, Sign In to add comment