在打开文件时启用编码格式file = open("yue.txt",‘w‘,encoding=‘utf-8‘)
import urllib.requestimport redata = urllib.request.urlopen(‘#‘).read().decode("utf-8")pat =‘<div class="name">(.*?)</div>‘pub = re.compile(pat).findall(data)fh = open("yue1.txt",‘w‘,encoding=‘utf-8‘)for x in range(0,len(pub)): print(pub[x]) fh.write(pub[x]+‘\n‘)fh.close()
原文地址:https://www.cnblogs.com/Syue/p/11135283.html
时间: 2024-10-11 20:39:55