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

Function get_page_html

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

Source from the content-addressed store, hash-verified

29
30# 获取页面的HTML代码(通过递归实现指定次数的重试操作)
31def get_page_html(seed_url, *, retry_times=3, charsets=('utf-8',)):
32 page_html = None
33 try:
34 if seed_url.startswith('http://') or \
35 seed_url.startswith('https://'):
36 page_html = decode_page(urlopen(seed_url).read(), charsets)
37 except URLError as err:
38 logging.error('[URL]', err)
39 if retry_times > 0:
40 return get_page_html(seed_url, retry_times=retry_times - 1,
41 charsets=charsets)
42 return page_html
43
44
45# 从页面中提取需要的部分(通常是链接也可以通过正则表达式进行指定)

Callers 1

start_crawlFunction · 0.70

Calls 1

decode_pageFunction · 0.70

Tested by

no test coverage detected