当前第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执行shell脚本 并动态传参 及subprocess基本使用
Python变量类型 -元组的实际运用与意义
Python和selenium开发环境搭建的图文教程
详解Python的命名规则
Python函数中参数的详细介绍
Python语言实现百度语音识别功能的实例
Python中5种连接字符串的方法
Python如何在 .format 中使用大括号
hash()是Python内置的吗
使用pip安装Python库的几种常用方法
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » 如何解决python写入html文件中乱码的现象(图文详解)