I'm trying to get product info from an online electronics store. My code uses BeautifulSoup but I'm not getting the results I want. Here's what I've got so far:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://example-electronics-store.com'
headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.content, 'lxml')
product_container = soup.find('div', class_='product-grid')
if product_container:
product_items = product_container.find_all('li', class_='product-item')
for item in product_items:
product_name = item.find('h3', class_='product-name').text.strip()
product_price = item.find('span', class_='price').text.strip()
product_link = item.find('a', class_='product-link')['href']
print(f'Name: {product_name}, Price: {product_price}, Link: {product_link}')
else:
print('No product container found')
I’m struggling to get the individual product details. Can someone help me figure out how to extract the product names, prices, and links from the <li>
elements? Thanks!