-
How can I scrape product data from Lazada Thailand using Python n BeautifulSoup?
When scraping Lazada Thailand, one of the key things to remember is to deal with dynamic content. While BeautifulSoup is great for parsing HTML, you’ll often need to combine it with requests to fetch the static HTML. However, when the data is rendered by JavaScript, you may need to use something like Selenium for full functionality. For now, let’s assume you’re dealing with static pages. By inspecting the page, you can locate the product names, prices, and possibly the ratings. You can then extract these by finding the appropriate tags with BeautifulSoup.
import requests from bs4 import BeautifulSoup url = 'https://www.lazada.co.th/catalog/?q=laptop' headers = {'User-Agent': 'Mozilla/5.0'} response = requests.get(url, headers=headers) soup = BeautifulSoup(response.text, 'html.parser') products = soup.find_all('div', {'class': 'c16H9d'}) for product in products: name = product.get_text() print(f'Product: {name}
Log in to reply.