Fork me on GitHub

python简单爬虫示例

#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提供了相关接口可以执行!

posted on 2016-05-24 23:45  mrdoor  阅读(399)  评论(0编辑  收藏  举报