Reputation: 570
I am creating a data scraper using scrapy. I shell the product url using
scrapy shell 'https://royalprint.pk/product/name-print-superhero-sweatshirt-011/'
and then run this command
In [43]: response.css('span.woocommerce-Price-currencySymbol::text').get()
Out[43]: 'Rs'
It only returns the currency symbol.
Here is the source code product image
Someone please correct me what I did wrong here ?
Regards
Upvotes: 1
Views: 1001
Reputation: 126
The span element you are referencing only contains Rs text.
<span class="woocommerce-Price-currencySymbol">Rs</span>
But the price information you want is after the closing tag of the span element.
The price is included in the bdi element. since we have other bdi elements on the webpage so we need to reference the exact one.
response.xpath("//p[@class='price']//bdi/text()").extract()
Upvotes: 0
Reputation: 2619
Its might help.
for price in response.css('p.price'):
print(price.xpath('./del/span/bdi/text()').get())
print(price.xpath('./ins/span/bdi/text()').get())
Upvotes: 2
Reputation: 18799
Nothing wrong really, but you just mistaken the element you need to get. I guess you want to get the price number, in that case you should use something like:
span.woocommerce-Price-amount bdi::text
as you can see, it's the bdi
element the one containing the information you want, not the inner span
Upvotes: 0