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:
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.
import requestsfrom requests.compat import urljoinfrom bs4 import BeautifulSoupbase_url = "https://books.toscrape.com/"titles = []images = []rates = []prices = []#ToDOprint("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.