Challenges: Scrape the Web Page Using Beautiful Soup

Scrape the book’s site using Beautiful Soup.

We'll cover the following

Problem statement

Write code to get book information from the first page of the Books to Scrape:

Press + to interact
First page of Books to Scrape website
First page of Books to Scrape website

Expected output

  • titles: List of all the books' titles.

  • images: List of all the images' URLs (valid URLs with the domain name).

  • rates: List of the number of stars for each book in a string format, example: ['one', 'two', 'three', ....].

  • prices: A price list for all of the books.

Note: Just scrape the first page, the code expects the four lists to have 20 elements each.

Press + to interact
import requests
from requests.compat import urljoin
from bs4 import BeautifulSoup
base_url = "https://books.toscrape.com/"
titles = []
images = []
rates = []
prices = []
#ToDO
print("Length of scraped titles: ", len(titles))
print("Length of scraped images: ", len(images))
print("Length of scraped rates: ", len(rates))
print("Length of scraped prices: ", len(prices))
print(titles)

Get hands-on with 1300+ tech skills courses.