March 2019
Beginner
490 pages
12h 40m
English
It is also important to verify if the label is returned when we use the find method. We may have written an incorrect label or try to get a label that is not on the page and this will return the None object, so we must verify if the object is None. This can be done using a simple conditional statement such as the one in this example.
You can find the following code in the handling_exceptions_tags.py file inside the beautifulSoup folder:
from urllib.request import urlopenfrom urllib.error import HTTPErrorfrom urllib.error import URLErrorfrom bs4 import BeautifulSoup try: html = urlopen("https://www.packtpub.com/")except HTTPError as e: print(e)except URLError: print("Server down or incorrect domain") ...Read now
Unlock full access