首页 > 编程语言 > 详细

Python 简单业务爬虫

时间:2018-04-26 15:29:07      阅读:146      评论:0      收藏:0      [点我收藏+]

如何快速下载贴吧图片呢?

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import urllib
import re

def getHtml(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)


Python 简单业务爬虫

原文:http://blog.51cto.com/dengaosky/2108112

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