python简单爬虫示例
#coding=utf-8
import
urllib
import
re
def
downloadPage(url):
h
=
urllib.urlopen(url)
return
h.read()
def
downloadImg(content):
pattern
=
r
'src="(.+?\.jpg)" pic_ext'
m
=
re.
compile
(pattern)
urls
=
re.findall(m, content)
for
i, url
in
enumerate
(urls):
urllib.urlretrieve(url,
"%s.jpg"
%
(i, ))
downloadImg(content)
针对图片的批量下载 urllib提供了相关接口可以执行!