标签:write pat python read close 文件乱码 name com coding
在打开文件时启用编码格式
file = open("yue.txt",‘w‘,encoding=‘utf-8‘)
import urllib.request
import re
data = 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()
标签:write pat python read close 文件乱码 name com coding
原文地址:https://www.cnblogs.com/Syue/p/11135283.html