def set_data (self, resp):
if not resp.text.strip ():
self.data = None
else:
ct = resp.headers.get ('content-type')
if ct is None or ct.find ('text/html') == 0:
h = html2text.HTML2Text()
h.ignore_links = True
text = h.handle(resp.text)
self.data = text
elif ct is None or ct.find ('text/') == 0:
self.data = resp.text.strip ()
else:
data = resp.json ()
if isinstance (data, dict):
self.data.update (data)
else:
self.data = data
if not str(resp.status_code).startswith("2"):
raise AssertionError ("%s %s\n%s\n%s" % (resp.status_code, resp.reason, "-" * (20 + len (resp.reason)), self))
评论列表
文章目录