python3 批量下载163网址图片


import os
import wget
import re

def get_path(fname,img_path):
    getpasth = re.compile(img_path)
    path_list  = []
    with open(fname) as fobj:
        for line in fobj:
            m = getpasth.search(line)
            if m:
                path_list.append(m.group())
    return path_list




if __name__ == "__main__":
    #下载163网页
    dst = '/tmp/163'
    fname =  '/tmp/163/163.html'
    url163 = 'http://www.163.com'
    if not os.path.exists(dst):
        os.mkdir(dst)
    if not os.path.exists(fname):
        wget.download(url163,fname)

    #获取163网页图片地址
    img_path = '(https|http)://[\w/.-]+\.(jpg|png|jpeg|gif)'
    img_list = get_path(fname,img_path)
    #通过图片地下载图片保存
    for path in img_list:
        wget.download(path,dst)

猜你喜欢

转载自blog.csdn.net/weixin_38642722/article/details/126708573