#!/usr/bin/env python
#coding:utf-8
import urllib, re
def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
return html
def getImage(html):
reg = r'src="(.+?\.jpg)"'
imgre = re.compile(reg)
imglist = re.findall(imgre, html)
#return imglist
x = 0
for imgurl in imglist:
urllib.urlretrieve(imgurl, '%s.jpg' % x)
x += 1
html = getHtml("https://baike.baidu.com/pic/%e5%bc%a0%e9%9f%b6%e6%b6%b5/148008/19671396/203fb80e7bec54e7fb488382be389b504ec26a82?fr=lemma&ct=cover#aid=19671396&pic=203fb80e7bec54e7fb488382be389b504ec26a82")
getImage(html)
这个脚本会爬取页面上的照片,并且给照片重命名,保存在当前的目录中。
转载于:https://blog.51cto.com/zidingyi/1886132