python写入文件乱码文图


在打开文件时启用编码格式
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()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM