分享一个Python爬虫小脚本

800阅读 0评论2013-04-04 八月飞霜
分类:Python/Ruby

此Python小脚本为抓取此页面: 下的所有jpg图像

'''
Created on 2013-4-2

@author: Administrator
'''
import re
import urllib

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

def getImg(html):
    reg = r'src="(.*?\.jpg)" width'
    imgreg = re.compile(reg)
    imglist = re.findall(imgreg, html)
    x = 0
    for imgurl in imglist:
        urllib.urlretrieve(imgurl, '%s.jpg' % x)
        x += 1
        
html = getHtml("")
getImg(html)
上一篇:Python备份脚本
下一篇:定制保存top输出信息的格式详解