I'm trying to scrape this for product names and prices.
There's a load more button at the bottom of the page, I've tried using postman to modify the form data and 'productBeginIndex':
and 'resultsPerPage':
seem to modify the number of products shown.
However, I'm unsure what's wrong with my code - it still returns the 24 products no matter how I tweak the values. I've tried using FormRequest.from_response()
but it still just returns 24 products.
import scrapy
class PriceSpider(scrapy.Spider):
name = "products"
def parse(self, response):
return [scrapy.FormRequest(url="https://www.fairprice.com.sg/baby-child",
method='POST',
formdata= {'productBeginIndex': '1', 'resultsPerPage': '1', },
callback=self.logged_in)]
def logged_in(self, response):
# here you would extract links to follow and return Requests for
# each of them, with another callback
name = response.css("img::attr(title)").extract()
price = response.css(".pdt_C_price::text").extract()
for item in zip(name, price):
scraped_info = {
"title" : item[0],
"value" : item[1]
}
yield scraped_info
Could someone please tell me what I'm missing? And how could I implement a loop to extract all the objects in the category?
Thank you so much!