在打开文件时启用编码格式
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]+' ')
fh.close()