当前位置:网站首页>【无标题】

【无标题】

2022-07-06 14:53:00 freshfox

#-*- coding:utf-8 -*-
from bs4 import BeautifulSoup
import  requests

def get_imgs(xml_name = 'output.xml'):

    file = open('1.html', encoding='utf-8').read()
    soup = BeautifulSoup(file, 'xml')
    count =0
    try :
        for node in soup.findChildren('img'):

            src = node['src']
            count =count+1
            if count > 3:
                break

            print ("src : " + src)
            response = requests.get(src)
            img = response.content
            path = '%s.jpg' % (count)
            with open(path, 'wb') as f:
                f.write(img)


    except Exception  as  e:
        print("get exception " + e)




get_imgs()

原网站

版权声明
本文为[freshfox]所创,转载请带上原文链接,感谢
https://blog.csdn.net/freshfox/article/details/125481281