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

python简单爬虫示例

时间:2016-05-25 00:31:36      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:

#coding=utf-8

 
import urllib
import re
 
def downloadPage(url):
    = urllib.urlopen(url)
    return h.read()
 
def downloadImg(content):
    pattern = r‘src="(.+?\.jpg)" pic_ext‘
    = re.compile(pattern)
    urls = re.findall(m, content)
 
    for i, url in enumerate(urls):
        urllib.urlretrieve(url, "%s.jpg" % (i, ))
 
content = downloadPage("http://tieba.baidu.com/p/2460150866")
downloadImg(content)
 
针对图片的批量下载 urllib提供了相关接口可以执行!

python简单爬虫示例

标签:

原文地址:http://www.cnblogs.com/mrdoor/p/5525461.html

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