import re
import time
from urllib.request import urlopen, urlretrieve


# 下载HTML
def getHtml(url):
    page = urlopen(url)
    html = page.read()
    return html


# 从html中解析出图片URL
def getImg(html):
    reg = r'src="(.*?\.jpg)"'
    imgre = re.compile(reg);
    htmld = html.decode('utf-8')
    imglist = imgre.findall(htmld)
    return imglist


# 下载处理
def imgDownload(imgUrl):
    urlretrieve(imgUrl, '%s.jpg' % time.time())


# 主函数
def main():
    url = 'https://www.52pago.com/chevereto/explore/recent/'
    html = getHtml(url)
    imglist = getImg(html)
    for imgurl in imglist:
        print(imgurl)
        imgDownload(imgurl)

        # 执行主函数


if __name__ == '__main__':
    main()
最后修改:2019 年 12 月 05 日 04 : 31 PM
如果觉得我的文章对你有用,请随意赞赏