-
Scrape product availability, price from Central Thailand’s using Python n Scrapy
Scraping Central Thailand’s e-commerce website using Scrapy is efficient when you want to extract structured data such as product availability and price. The first step is to navigate to the specific product category page, where you can locate the price and availability by inspecting the HTML elements. You can use Scrapy’s XPath or CSS selectors to target the specific data fields. One challenge when scraping product availability is handling items that may not be listed as “in stock” but are available via special request. The next challenge is to ensure you paginate through product pages for a complete dataset.
import scrapy class CentralEcommerceSpider(scrapy.Spider): name = 'central_ecommerce' start_urls = ['https://www.central.co.th/en/product-category'] def parse(self, response): products = response.css('div.product-item') for product in products: title = product.css('div.product-name::text').get() price = product.css('span.product-price::text').get() availability = product.css('span.availability-status::text').get() yield { 'title': title.strip(), 'price': price.strip(), 'availability': availability.strip(), } # Pagination handling next_page = response.css('a.next-page::attr(href)').get() if next_page: yield response.follow(next_page, self.parse)
Log in to reply.