web scraping in Python using the popular library BeautifulSoup

# Importing Required Libraries
import requests
from bs4 import BeautifulSoup

# Send a GET request to the URL
url = "https://www.example.com"
response = requests.get(url)

# Parsing the HTML content using BeautifulSoup
soup = BeautifulSoup(response.content, 'html.parser')

# Extracting information from the HTML content
title = soup.title.text
links = soup.find_all('a')

# Printing the extracted information
print(title)
for link in links:
    print(link.get('href'))

n this example, we first import the necessary libraries – requests and BeautifulSoup. We then send a GET request to the desired URL and parse the HTML content using BeautifulSoup. We extract information from the HTML content, such as the title and links, and print the results.

Please note that web scraping may be restricted by the website’s terms of service or legal restrictions, so make sure to check and follow these rules before scraping any website.

Leave a Reply