Kizspy Question: 40
(Choose 1 answer)
FDG VERT LOW LOV
You're scraping an e-commerce website to extract product information. Each product is listed in a <div> with
the class "product-item". Inside each product <div>, the product name is contained within a <h3> tag with the
class "product-name", and the price is contained within a <span> tag with the class "product-price". Write a
code snippet using BeautifulSoup to extract the last prices of last product on the page.
from bs4 import BeautifulSoup
#Sample HTML content
html content = ""
<div class="product-item">
<h3 class="product-name">Product 1</h3>
<span class="product-price">$19.99</span>
</div>
<div class="product-item">
<h3 class="product-name">Product 2</h3>
<span class="product-price">$29.99</span>
</div>
<!-- More product items -->
<div class="product-item">
<h3 class="product-name">Product N</h3>
<span class="product-price">$49.99</span>
</div>
# Parse the HTML content
soup = BeautifulSoup(html_content, 'html.parser')
# Extract the last product's price
last_product_price = choose appropriate code here
print("Last product's price:", last_product_price)
A. soup.find_all('div', class_='product-item')[-1].find('span', class_='product-price').text
B. soup.find_all('div', class_='product-item')[-1].find('h3', class_='product-name').text
C. soup.find_all('div', class_='product-price')[-1].text
D. soup.find_all('div', class_='product-name')[3].find('span', class_='product-price').text