Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- def extract_h1_tag(url):
- try:
- response = requests.get(url)
- response.raise_for_status() # Raises error for bad status codes
- soup = BeautifulSoup(response.text, 'html.parser')
- h1_tag = soup.find('h1')
- if h1_tag:
- print(f"<h1> tag content: {h1_tag.text.strip()}")
- else:
- print("No <h1> tag found on the page.")
- except requests.exceptions.RequestException as e:
- print(f"Error fetching the webpage: {e}")
- # Example usage
- extract_h1_tag("https://csszengarden.com")
Advertisement
Add Comment
Please, Sign In to add comment