Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2131357
  • 博文数量: 103
  • 博客积分: 206
  • 博客等级: 入伍新兵
  • 技术积分: 1819
  • 用 户 组: 普通用户
  • 注册时间: 2012-09-12 10:24
个人简介

效字当先,以质为本。

文章分类
文章存档

2019年(2)

2018年(4)

2017年(7)

2016年(3)

2015年(14)

2014年(33)

2013年(31)

2012年(9)

分类: Python/Ruby

2014-03-16 19:48:58


点击(此处)折叠或打开

  1. import re
  2. import urllib
  3. import os

  4. def getHtml(url):
  5.     page_html = urllib.urlopen(url).read()
  6.     return page_html

  7. def getImg(page_html,imgdir):
  8.     reg = r'src="(.*?\.jpg)" width'
  9.     imgre = re.compile(reg)
  10.     imglist = re.findall(imgre,page_html)
  11.     x = 0
  12.     for i in imglist:
  13.         imgfile = os.path.join(os.path.abspath("%s%s.jpg")%(imgdir,x))
  14.         urllib.urlretrieve(i,imgfile)
  15.         x = x+1

  16. if __name__ == '__main__':
  17.     page_html = getHtml("")
  18.     getImg(page_html,"img/")

阅读(1687) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~