chuky pedro
chuky pedro

Reputation: 745

How to extract text field with css using Xpath

I am trying to extract price from html using the below xpath expression.

<div class="-hr -pvs -mtxs" data-prd-prices="">
    ::before
    <span dir="ltr" data-price="" class="-b -ltr -tal -fs24">₦ 3,550</span>

</div>

my_xpath = //div[@class='-hr -pvs -mtxs']/span/text()

The xpath expression locates the price but when I try to scrape the price I get this

 [<Selector xpath="//div[@class='-hr -pvs -mtxs']/span/text()" data='₦ 3,550'>]

I know that this is coming from the ::before in the html tag. what does that mean and how can I extract the price

when I hover the ::before in the chrome developer tool I get this

div.-hr -pvs -mtxs::before

Upvotes: 0

Views: 27

Answers (1)

Abbas Maalik Wattoo
Abbas Maalik Wattoo

Reputation: 129

You have done the right thing but you are not extracting the data.

my_xpath = "//div[@class='-hr -pvs -mtxs']/span/text()"
extracted_data = response.xpath(my_xpath).getall()

should do the job.

Upvotes: 1

Related Questions