python网页快速保存程序
作者:互联网
from urllib.request import urlopen
def copypage(url,name):
r=urlopen(url) #打开网页
file=r.read().decode("utf-8") #网页读取到file文件中,编码格式为utf-8
path=r"C:\Users\Administrator\Desktop" #电脑桌面路径
path2=path+"\\"+name+".html" #加上文件名后的保存路径
with open(path2,mode="w",encoding="utf-8") as f: #将读取的file文件,写入到完整路径中去
f.write(file)
print("保存成功,路径:"+path2)
print("{:*^45}".format("", "*"))
print("{:*^40}".format("网页快速保存程序","*"))
url=input("输入网址:")
name=input("输入文件名:")
copypage(url,name)
标签:path2,网页,name,python,保存,url,file,print 来源: https://blog.csdn.net/weixin_47401101/article/details/121004341