import <span class="wp_keywordlink_affiliate"><a href="https://www.168seo.cn/tag/cchardet" title="View all posts in cchardet" target="_blank">cchardet</a></span> # html2 =requests.get("http://www.baidu.com/").content #注意 不能用text方法,text方法返回的是unicode code= <span class="wp_keywordlink_affiliate"><a href="https://www.168seo.cn/tag/cchardet" title="View all posts in cchardet" target="_blank">cchardet</a></span>.detect(html2)['encoding'] print code
1
2
3
4
5
|
import
cchardet
#
html2
=
requests
.
get
(
"http://www.baidu.com/"
)
.
content
#注意 不能用text方法,text方法返回的是unicode
code
=
cchardet
.
detect
(
html2
)
[
'encoding'
]
print
code
|
速度是chardet的好几十倍,非常之快