get encoding from response date

fix #622

Signed-off-by: Zhang Ning <zhangn1985@gmail.com>
This commit is contained in:
Zhang Ning 2015-09-03 17:36:02 +08:00
parent 25c769df2e
commit 9abf54ead5

View File

@ -192,7 +192,8 @@ def get_content(url, headers={}, decoded=True):
# Decode the response body # Decode the response body
if decoded: if decoded:
charset = match1(response.getheader('Content-Type'), r'charset=([\w-]+)') charset = match1(response.getheader('Content-Type'), r'charset=([\w-]+)') or \
match1(str(data), r'charset=([\w-]+)')
if charset is not None: if charset is not None:
data = data.decode(charset) data = data.decode(charset)
else: else: