skip to Main Content

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

3

Answers


  1. 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

    Login or Signup to reply.
  2. 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())
    
    Login or Signup to reply.
  3. 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()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search