Created
December 28, 2014 14:30
-
-
Save devpruthvi/0dca5521a60b21528147 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### A program to download wallpapers from alphacoders.com | |
###Author: N.V.Pruthvi Raj, Anantapur, India. | |
###Date: 23/12/2014 | |
import requests | |
import shutil | |
import re | |
import os | |
from bs4 import BeautifulSoup | |
url = 'http://wall.alphacoders.com/by_sub_category.php?id=173173&name=Naruto&page=1' | |
baseurl = url[0:url.find('page=')+5] | |
r = requests.get(url) | |
soup = BeautifulSoup(r.content) | |
downloadable = [] | |
noofpages = -1 | |
alla = soup.find_all("a") | |
def getnopages(noofpages): | |
for link in alla: | |
href = str(link.get('href')) | |
if href.find('page') >=0: | |
currpages = int((re.findall('\d+',href))[-1]) | |
if currpages > noofpages: | |
noofpages = currpages | |
return noofpages | |
noofpages = getnopages(noofpages) | |
def getlink(url): | |
r = requests.get(url) | |
soup = BeautifulSoup(r.content) | |
alla = soup.find_all("a") | |
for link in alla: | |
href = str(link.get('href')) | |
if href.startswith('http://uploads'): | |
downloadable.append(href) | |
print(noofpages) | |
for each in range(1,noofpages+1): | |
getlink(baseurl+str(each)) | |
print(len(downloadable)) | |
def downloadfiles(downloadable): | |
no = 0 | |
os.chdir('I:/emma/') | |
for url in downloadable[0:]: | |
print(no) | |
response = requests.get(url, stream=True) | |
with open('img'+str(no)+'.jpg', 'wb') as out_file: | |
shutil.copyfileobj(response.raw, out_file) | |
no+=1 | |
del response | |
downloadfiles(downloadable) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment