python — 获取网页图片资源
程序员文章站
2022-05-06 14:05:48
...
Python 获取网络资源
# coding=UTF-8
import re
import urllib
def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
#html = html.decode('UFT-8')
return html
def getImg(html):
reg = r'src="(.*?\.jpg)"'
imgre = re.compile(reg)
imglist = re.findall(imgre,html)
print(imglist)
x= 0
for imgurl in imglist:
pathName="/Users/gjh/Desktop/图片缓存文件/"+str(x)+".jpg"
urllib.urlretrieve(imgurl,pathName)
print("正在下载.......")
x+=1
#htmlStr = "https://max.book118.com/index.php?g=Home&m=NewView&a=index&aid=8057045117001121&v=20190819"
htmlStr = "http://localhost:63342/untitled/index_2.html?_ijt=soopna1lkuo4o7446ed9a6rc9a"
html = getHtml(htmlStr)
print(html)
getImg(html)
上一篇: JBOSS使用
下一篇: JVM性能调优监控工具 - jdb