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

Function decode_page

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

Source from the content-addressed store, hash-verified

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

Callers 1

get_page_htmlFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected