发布时间:2019-09-27 16:29:27编辑:Run阅读(4170)
requests-html 捕获访问超时异常
from requests_html import HTMLSession import requests session = HTMLSession() url = 'https://www.zaful.com/men-e_118/?featuring=454613605,454613605,454620801,454622001,454615201,454622901"\n' try: r = session.get(url=url, timeout=0.1) if r.status_code == 200: title_ret = r.html.xpath("/html/head/title/text() | //title/text()") if title_ret: title_ret = title_ret[0].strip().replace("\n", "") print(title_ret) else: print(r.status_code) except requests.exceptions.ReadTimeout as read_timeout: print(read_timeout) except requests.exceptions.ConnectTimeout as connect_timeout: print(connect_timeout) except Exception as e: print(e) finally: session.close()
执行结果
HTTPSConnectionPool(host='hk.zaful.com', port=443): Read timed out. (read timeout=0.1)
下一篇: Reuqests-html教程
47616
46004
36920
34486
29096
25742
24578
19725
19265
17766
5581°
6167°
5703°
5757°
6718°
5496°
5501°
6001°
5975°
7306°