#!/usr/bin/env python #coding=utf-8 ‘‘‘ @ 这个脚本会将指定网页中的壁纸图片下载到本地 ‘‘‘ import urllib import re def get_html_info(url): ‘‘‘ @获取网页源代码 ‘‘‘ html = urllib.urlopen(url) html_info = html.read() return html_info def get_img(info): ‘‘‘ @ 获取通过正则表达式匹配到的图片列表 ‘‘‘ bloke_re = re.compile(r‘class="BDE_Image" src="(.+?\.jpg)"‘) bloke_imgs = re.findall(bloke_re, html_info) return bloke_imgs url = ‘http://tieba.baidu.com/p/4015768244‘ html_info = get_html_info(url) #网页原码 all_imgs = get_img(html_info) #图片列表 i = 1 for img in all_imgs: urllib.urlretrieve(img, ‘%s.jpg‘ % i) i += 1 else: print "Done..."
原文地址:http://anonxiaozi.blog.51cto.com/8139771/1692705