Skip to content

COMBINING WITH REQUESTS - Web scraping simulation

Python
#!/usr/bin/env python3
"""COMBINING WITH REQUESTS - Web scraping simulation"""
from bs4 import BeautifulSoup
# Simulating HTML response
html_response = """
<html><head><title>Product Page</title></head>
<body>
<h1 class="product-title">Laptop Computer</h1>
<span class="price">$999.99</span>
<div class="description">High-performance laptop</div>
<ul class="features">
    <li>16GB RAM</li>
    <li>512GB SSD</li>
    <li>Intel i7</li>
</ul>
</body></html>
"""
soup = BeautifulSoup(html_response, 'html.parser')
print("Web Scraping Example:")
title = soup.find(class_='product-title').string
price = soup.find(class_='price').string
description = soup.find(class_='description').string
features = [li.string for li in soup.select('.features li')]
print(f"  Title: {title}")
print(f"  Price: {price}")
print(f"  Description: {description}")
print(f"  Features: {features}")