ITPub博客

首页 > IT职业 > IT职场 > Python 简单业务爬虫

Python 简单业务爬虫

IT职场 作者:cartoonfish 时间:2021-09-09 09:36:47 0 删除 编辑


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


#!/usr/bin/python# -*- coding: UTF-8 -*-import urllibimport re def getHtml(url):    page = urllib.urlopen(url)    html = page.read()    return html def getImg(html):    reg = r'class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="(.+?.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)


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1409/viewspace-2810960/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Redis持久化机制
请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    96
  • 访问量
    514