记录python获取html节点,根据路径复制文件
-
已经保存下来的网页,获取里面指定的文件名称,然后复制到另外文件夹
-
#用于解析html节点 from bs4 import BeautifulSoup as bs import re #根据路径复制文件 import shutil with open("C:\\\\\Users\\\\\nsk\\\\\Desktop\\\\\1\\\\\1.html","r", encoding='UTF-8') as f: html=f.read().encode("utf-8") html = bs(html,'html.parser') content = str(html.select("article")) print(content) ls = re.findall(r'src=.*?jpeg',content) ll = \\\[\\\] for i in ls: ll.append(i.replace('src="./',"C:/Users/nsk/Desktop/1/")) for i in ll: shutil.copy(i,"C:/Users/nsk/Desktop/1/image")