You can download this code by clicking the button below.
This code is now available for download.
This function extracts the title of a web page from a given URL. It uses the requests library to send an HTTP request and BeautifulSoup to parse the HTML content.
Technology Stack : Python, requests, BeautifulSoup
Code Type : Function
Code Difficulty : Intermediate
def extract_title_from_url(url, soup):
# This function extracts the title of a web page from a given URL using BeautifulSoup
# Send a GET request to the URL
response = requests.get(url)
# Parse the HTML content of the page with BeautifulSoup
soup = BeautifulSoup(response.text, 'html.parser')
# Find the title tag
title_tag = soup.find('title')
# Extract and return the title text
return title_tag.get_text() if title_tag else 'No title found'