当前第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的json.dumps()和json.loads()
name是Python的标识符吗
什么是Python返回函数?(实例解析)
在哪里卸载Python
认识什么是Python?Python的优点和缺点
Python的while如何使用
Python适合游戏开发吗
Python怎么安装?(教程图解)
Python适合在什么系统
Python函数之classmethod()
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » 如何解决python写入html文件中乱码的现象(图文详解)