#!/usr/bin/env python# -*- coding:utf-8 -*-import urllib.requestimport re #获取源码def gethtml(): papg = urllib.request.urlopen(‘https://www.4493.com/‘) html = papg.read().decode(‘gbk‘) #print(html) return html #下载图片def getimg(html): imgre = re.compile(r‘ lazysrc="(.*?)" ‘) imglist = re.findall(imgre,html)#匹配 print(imglist) x = 0 for imgurl in imglist: urllib.request.urlretrieve(imgurl, ‘D:\学习资料\pic\%s.jpg‘ % x) x += 1 html = gethtml()getimg(html)
时间: 2024-12-26 01:02:28