我想处理http.client.BadStatusLine: ''
异常。
我在Python3号上。我的密码是
import http.client
try:
req = urllib.request.Request(url, headers={'User-Agent': 'Chrome/51'})
html = urllib.request.urlopen(req).read()
soup = BeautifulSoup(html,"html.parser")
return soup
except http.client.HTTPException as eror:
print("Boom")
我读了stackOverFloeQuestion和this,但听不懂。有什么帮助吗?你知道吗
你需要下定决心:-)。您可以使用
http.client
或urllib.request
,但不应使用其中一个,然后尝试从另一个捕获错误。如果你想坚持urllib.request请求,要捕获的类是urllib.error.HTTPError
。你知道吗也许在您的情况下使用Requests更合适,这是一个更高级的http库。你知道吗
相关问题 更多 >
编程相关推荐