雕刻时光

just do it……nothing impossible
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

python下爬某个网页的图片

Posted on 2014-04-25 19:06  huhuuu  阅读(495)  评论(0编辑  收藏  举报
#coding=utf-8

import re
import urllib

def getHtml(url): #获取url对应得源码 page = urllib.urlopen(url) html = page.read() return html def getImg(html): #获取 reg = r'src="(.+?\.jpg)" pic_ext' imgre = re.compile(reg) imglist = re.findall(imgre,html) x = 0 for imgurl in imglist: urllib.urlretrieve(imgurl,'%s.jpg' % x) #下载文件到本地,并且重命名 x+=1 html = getHtml("http://tieba.baidu.com/p/2460150866") #将这个页面的图片都爬下来 #print getImg(html)

 参考:http://www.cnblogs.com/fnng/p/3576154.html