Attempting to scrape data from this website:
After retrieving all elements using the following code:
products = response.xpath("//ul[@class='products']//ancestor::li")
I attempted to extract prices for all elements in the scrapy shell. Initially, I used the following code:
>>> for p in products:
... p.xpath("//span[@class='price']//child::bdi/text()").get()
...
'134.99'
'134.99'
'134.99'
'134.99'
'134.99'
'134.99'
'134.99'
'134.99'
'134.99'
It appears that only the first price is being retrieved despite the loop.
Then, I tried using CSS selectors and it worked as expected:
>>> for p in products:
... p.css("span.price bdi::text").get()
...
'134.99'
'49.99'
'39.99'
'39.99'
'39.99'
'129.99'
'24.99'
'49.99'
'119.99'
The xpath-selector approach seems to not work as intended. Why could this be happening?