当前第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文件中乱码的现象(图文详解)的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
Python中add函数怎么用
如何使用 pylint 来规范 Python 代码风格(来自ibm)_Python
Python基础教程系列目录,最全的Python入门系列教程!
Python如何使用xlrd实现读取合并单元格
基于Python 装饰器装饰类中的方法
Python百分号怎么打
Python用什么ide
小甲鱼零基础入门学习Python视频教程
Python类中怎么定义方法
Python中有关filter的用法详解
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » 如何解决python写入html文件中乱码的现象(图文详解)