安装 Python

安装 Pip

sudo easy_install pip

安装 BeautifulSoup

#!/usr/bin/python

#-*- coding: utf-8 -*-

#encoding=utf-8

import urllib2

import urllib

import os

from bs4 import BeautifulSoup

#

#def

def getAllImageLink():
    
    i=1;
    
    #while
    
    while(i<2):
        
        #http://www.dbmeizi.com/category/11?p=0
        
        #html = urllib2.urlopen('http://www.dbmeizi.com/category/11?p=%s'%(i-1)).read()
        html = urllib2.urlopen('http://www.jczj123.net/index2.htm')
        
        i=i+1;
                
        #html = urllib2.urlopen('http://www.dbmeizi.com').read()
                
        soup = BeautifulSoup(html, "lxml")
                    
                    #
                    
        liResult = soup.findAll('img')
        
        m=0
        print liResult
        for li in liResult:
                    m=m+1
                    print("linkk")
                    imageEntityArray = li
                    #find img
                    
                    link=li.get('src')
                    #print(link)
                    imageName=m
                    filesavepath ='/Users/apple/Desktop/testpy/%s.jpg' % imageName
                        
                    value=link.split('http')
                    
                    if len(value)> 1:

                        urllib.urlretrieve(link,filesavepath)

                        print filesavepath


if __name__ == '__main__':  
    
    getAllImageLink()





Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐