BeautifulSoup and requests together make for a powerful scraping combination, especially for sites like Lazada Thailand that display a lot of product data on each page. If the page you are scraping is not fully dynamic, you can use BeautifulSoup to extract the names and prices directly. One trick is to handle pagination, which allows you to scrape all the products listed under various categories. Additionally, remember to parse the content by looking at different classes used in the site’s structure.
import requests
from bs4 import BeautifulSoup
url = 'https://www.lazada.co.th/catalog/?q=electronics'
headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
# Find all products in the catalog
product_elements = soup.find_all('div', class_='c3i7w0')
for product in product_elements:
name = product.find('div', class_='c16H9d').text
price = product.find('span', class_='c13VH6').text
print(f'Product: {name}, Price: {price}')