Question: # starter code import requests from bs4 import BeautifulSoup import pandas as pd Please don't import anything else, thanks. www. books.toscrape.com is a mock online
# starter code
import requests from bs4 import BeautifulSoup import pandas as pd
Please don't import anything else, thanks.

www. books.toscrape.com is a mock online book store website, with a list of books that include prices, ratings, and inventory. It is set up for people to practise Web scraping. Question 2.1 Write code to scrape product information for all books in the travel genre (https://books.toscrape.com/catalogue/category/books/travel_2/index.html). The pieces of information you need to extract for each book include the book title, the URL of the thumbnail image, the price, and the rating. Write the scraped data into a pandas DataFrame. url = "https://books.toscrape.com/" \# write your code below Question 2.2 Extend your code in Question 2.1 to scrape product information for books in multiple genres (e.g., "Travel", "Mystery", "Historical Fiction", "Sequential Art", "Classics", and "Philosophy"; the 1st 6 subcategories listed on the side navigation bar). Then for each book record, include the genre information as one of its characteristics. Note that for genres having multi-page results, your Python code only needs to process the 1st result page. Tips: - Extract the URLs of those 1st results pages by parsing the HTML that renders the side navigation bar. - Write a for loop to repeat the web scraping procedure for each of these URLs. url = "https://books.toscrape.com/" genres = ["Travel", "Mystery", "Historical Fiction", "Sequential Art", "Classics", "Philosophy"] \# write your code below Bonus Question Extend your code further to enable it to process multi-page results. - Tips: For a non-existent web page, the response from the website contains a status code, which can be accessed and tested as follows: response.status_code ==404 \# write your code below
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
