Web scraping is a technique employed to extract data from websites. This data can be used for a variety of purposes such as market research, data analysis, and price monitoring. In this article, we will be using the Beautiful Soup library to scrape data from a website.
Beautiful Soup is a Python library that is used for parsing HTML and XML documents. It is a very versatile library and can be used for a variety of purposes such as data scraping, data analysis, and web development.
In this article, we will be scraping data from the website We will be extracting the title, the URL, and the price of the product from the website.
The first step is to import the Beautiful Soup library.
import bs4
Next, we will create a variable called url and assign the URL of the website to it.
url = ‘
Next, we will create a variable called soup and assign the Beautiful Soup object to it.
soup = bs4.BeautifulSoup(url)
Next, we will use the find_all() method to extract all of the titles from the website.
titles = soup.find_all(‘h2’)
Next, we will use the find_all() method to extract all of the URLs from the website.
urls = soup.find_all(‘a’)
Next, we will use the find_all() method to extract all of the prices from the website.
prices = soup.find_all(‘span’)
Next, we will print the titles, URLs, and prices of the products.
print(‘The titles of the products are:’)
for title in titles:
print(title.text)
print(‘The URLs of the products are:’)
for url in urls:
print(url.get(‘href’))
print(‘The prices of the products are:’)
for price in prices:
print(price.text)