首页 > 编程语言 > 详细

简单 python爬虫 <2>

时间:2015-09-08 15:33:48      阅读:301      评论:0      收藏:0      [点我收藏+]
#!/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..."


简单 python爬虫 <2>

原文:http://anonxiaozi.blog.51cto.com/8139771/1692705

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!