【Educoder实训平台作业】网页图片批量获取 ※(依据国防科大招生网新版更新)

第1关:图片下载※

import urllib.request as req
from PIL import Image  
def savepng(path):
    im = Image.open(path)
    im = im.convert('RGBA')
    x,y = im.size    
    p = Image.new('RGBA', im.size, (33,79,55))
    p.paste(im, (0, 0, x, y), mask=im.split()[3])
    p.save('img/logo.png')
    p.close()
if __name__ == '__main__':
    path="img/logo.png"
    # **********begin********* #
    path = req.urlopen('https://www.nudt.edu.cn/bkzs/images/logo_01.png')
    # **********end********** #
    savepng(path)

第2关:图片链接提取※

import urllib.request as req
import re
def getHTML(url):
    # *********begin********* #
    webpage = req.urlopen(url)
    webdata = webpage .read()
    html = webdata.decode( 'utf-8')
    return html
    # *********end********* #
def getImgUrls(html):
    # **

你可能感兴趣的:(python,html,开发语言)