-
How can I scrape product details from JD Central Thailand using Python n Scrapy?
JD Central Thailand is a major e-commerce platform where you can scrape various product details, such as price, availability, and category, using Scrapy. The first step is to inspect the product page’s HTML structure, as JD Central often uses complex layouts with product listings inside specific div tags. Scrapy’s XPath or CSS selectors can then be used to extract these details. Additionally, some pages may have AJAX-loaded data, so it’s important to ensure that the data you need has been fully loaded before scraping. Once you have the data, you can store it in a database or a CSV file.
import scrapy class JDProductScraper(scrapy.Spider): name = 'jd_product_scraper' start_urls = ['https://www.jd.co.th/th/products'] def parse(self, response): for product in response.css('div.product-item'): 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(), } next_page = response.css('a.pagination-next::attr(href)').get() if next_page: yield response.follow(next_page, self.parse)
Log in to reply.