python简单爬虫示例

时间:2023-03-10 01:18:08
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提供了相关接口可以执行!