MCPcopy Create free account
hub / github.com/ZiniuLu/Python-100-Days / decode_page

Function decode_page

Day66-75/code/example05.py:18–27  ·  view source on GitHub ↗
(page_bytes, charsets=('utf-8',))

Source from the content-addressed store, hash-verified

16
17# 通过指定的字符集对页面进行解码(不是每个网站都将字符集设置为utf-8)
18def decode_page(page_bytes, charsets=('utf-8',)):
19 page_html = None
20 for charset in charsets:
21 try:
22 page_html = page_bytes.decode(charset)
23 break
24 except UnicodeDecodeError:
25 pass
26 # logging.error('[Decode]', err)
27 return page_html
28
29
30# 获取页面的HTML代码(通过递归实现指定次数的重试操作)

Callers 1

get_page_htmlFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected