首页 » Program » Python » 正文

Python collect animal‘s pictures

I use python to collect some animal’s pictures,this is a little crawler.As a matter of fact,python is very useful!

#coding:utf-8

import urllib,re

def gethtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html

x = 0

def getimg(html):
    imgre = re.compile(r'<img src="(.*?)" ')
    imglist = re.findall(imgre,html)

    for imgurl in imglist:
        print imgurl
        global x

        urllib.urlretrieve(imgurl,'E:\\python_pic_vid_etc\get_animal_pic\%s.jpg'%x)
        print 'downloading %s'%x
        x+=1
        

for i in range(1,10):
    url = 'http://www.ivsky.com/tupian/dongwutupian/index_%s.html'%i
    html = gethtml(url)
    getimg(html)

Comment