I am trying to get all the 'a' tags which are used for links and also the the 'form' tag. The code that I have written fetches the whole page.
import requests
from requests.exceptions import HTTPError
for url in ['http://www.example.com', 'http://mail.example.com']:
try:
response = requests.get(url)
# If the response was successful, no Exception will be raised
response.raise_for_status()
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}') # Python 3.6
except Exception as err:
print(f'Other error occurred: {err}') # Python 3.6
else:
response.encoding = 'utf-8' # Optional: requests infers this internally
print(response.text)
I can use regular expressions to get a specific thing from the page, but I don't know how to get the entire contents of a particular tag.
Thanks