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

Function get_page_html

Day66-75/code/example01.py:25–34  ·  view source on GitHub ↗
(seed_url, *, retry_times=3, charsets=('utf-8',))

Source from the content-addressed store, hash-verified

23
24# 获取页面的HTML代码(通过递归实现指定次数的重试操作)
25def get_page_html(seed_url, *, retry_times=3, charsets=('utf-8',)):
26 page_html = None
27 try:
28 page_html = decode_page(urlopen(seed_url).read(), charsets)
29 except URLError:
30 # logging.error('URL:', error)
31 if retry_times > 0:
32 return get_page_html(seed_url, retry_times=retry_times - 1,
33 charsets=charsets)
34 return page_html
35
36
37# 从页面中提取需要的部分(通常是链接也可以通过正则表达式进行指定)

Callers 1

start_crawlFunction · 0.70

Calls 1

decode_pageFunction · 0.70

Tested by

no test coverage detected