python 多网站采集,解决编码问题

import chardet

def get_charset(str):
    return chardet.detect(str)['encoding']

html = '' # bytes 字节串
charset = get_charset(html)
decoded_html = html.decode(charset, 'ignore')
print(decoded_html)

 

posted @ 2017-05-22 14:13  捕蛇者说  阅读(230)  评论(0编辑  收藏  举报