当前第2页 返回上一页
使用open方法的一个参数,名为encoding=” “,加入encoding=”utf-8”即可
1 2 3 4 5 6 7 8 | # 爬虫未使用cookiefrom urllib import requestif __name__ == '__main__' :
url = "http://www.renren.com/967487029/profile"
rsp = request.urlopen(url)
html = rsp.read().decode() with open( "rsp.html" , "w" ,encoding= "utf-8" ) as f: # 将爬取的页面
print (html)
f.write(html)
|
运行结果

感谢大家的阅读,希望大家收益多多。
本文转自: https://blog.csdn.net/qq_40147863/article/details/81746445
推荐教程:《python教程》
以上就是如何解决python写入html文件中乱码的现象(图文详解)的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
ansible作为Python模块库使用的方法
Python中django图书人物适配系统的实现方法(前端)
tensorflow用Python哪个版本更好?
Python怎么调用api实现智能回复功能
Python global用法
Python中怎么打开文件夹
普通人学Python有用吗
Python中range()函数和list的比较
Python装饰器-限制函数调用次数的方法(10s调用一次)
Python数据分析实战之 概述数据分析
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » 如何解决python写入html文件中乱码的现象(图文详解)