How to Use Reptile for iOS Programmer (2)

原创
2015/03/05 16:37
阅读数 44

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?

Let change some code in the source code like this:

#!/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!



展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部