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

Method fetch

Day66-75/code/main_redis.py:62–70  ·  view source on GitHub ↗
(self, current_url, *, charsets=('utf-8', ),
              user_agent=None, proxies=None)

Source from the content-addressed store, hash-verified

60
61 @Retry()
62 def fetch(self, current_url, *, charsets=('utf-8', ),
63 user_agent=None, proxies=None):
64 thread_name = current_thread().name
65 print(f'[{thread_name}]: {current_url}')
66 headers = {'user-agent': user_agent} if user_agent else {}
67 resp = requests.get(current_url,
68 headers=headers, proxies=proxies)
69 return decode_page(resp.content, charsets) \
70 if resp.status_code == 200 else None
71
72 def parse(self, html_page, *, domain='m.sohu.com'):
73 soup = BeautifulSoup(html_page, 'lxml')

Callers 1

runMethod · 0.45

Calls 1

decode_pageFunction · 0.70

Tested by

no test coverage detected