How to Use Reptile for iOS Programmer (2)

Last time we have write the python code to save all the images from one web page, but if one web page have "pagination", so how to get all the images from all the pages? html

Let change some code in the source code like this: python

#!/usr/bin/python
#-*- coding: utf-8 -*-
#encoding=utf-8
import urllib2
import urllib
import os
from BeautifulSoup import BeautifulSoup
def getAllImageLink():
    for i in range(0, 10):
        url = 'http://www.dbmeizi.com/?p=%d' % i
        if (i == 0):
            url = 'http://www.dbmeizi.com'
        html = urllib2.urlopen(url).read()
        
        soup = BeautifulSoup(html)
        liResult = soup.findAll('li',attrs={"class":"span3"})
        for li in liResult:
            imageEntityArray = li.findAll('img')
            for image in imageEntityArray:
                link = image.get('data-src')
                imageName = image.get('data-id')
                filesavepath = '/Users/blues/Desktop/meizipicture1/%s.jpg' % imageName 
                urllib.urlretrieve(link,filesavepath)
                print filesavepath 
if __name__ == '__main__':
    getAllImageLink()

like this, you can get all the "meizi" from the dbmeizi.com. Haha! web

相關文章
相關標籤/搜索