码迷,mamicode.com
首页 > 编程语言 > 详细

Python实现简单抓取功能

时间:2017-06-20 16:27:56      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:odi   logs   lib   ret   tps   http   爬虫   pre   简单   

一直以来都想好好学习Python,但是每次学习了从基础感觉学了一会就感觉没意思。今天学习一下爬虫,也算是自己学python的目的吧,但是在学习过程中遇到很多困难,但幸好遇到了一篇好博文,分享给大家:http://www.cnblogs.com/fnng/p/3576154.html

源码:

#encoding : utf-8
import urllib
import  re
def getHtml(url):
    page = urllib.urlopen(url)
    html =page.read()
    return html

def getImg(html):
    reg =  rsrc="(.+?\.jpg)" size
    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("https://tieba.baidu.com/p/5154456009")
print getImg(html)

 

Python实现简单抓取功能

标签:odi   logs   lib   ret   tps   http   爬虫   pre   简单   

原文地址:http://www.cnblogs.com/Mr0wang/p/7054468.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!