mkumars
mkumars

Reputation: 533

Web-scraping specific value from webpage to Google Sheets

I am trying to scrape some data from a website, but I only need a specific value from the website to be shown in Google Sheets.

Now what I am trying is to use the IMPORTXML function.

The website that I am trying to get data is https://dps.psx.com.pk/company/TRG I need the price specifically i.e. Rs. 172 (or whatever it may be at a certain time) - I need only the price but if currency is showing up e.g. Rs.172 that would be fine as well

Value I want in Google Sheet The highlighted line is the value when I inspect element from website

So far I am trying this and it only returns #N/A

=IMPORTXML(A1,"//span[@class='quote__close']")

Where A1 is the cell with the link in it.

From the web page I need the value 172.72 in the sheet and when I inspect element it shows what is displayed in the second screenshot

Upvotes: 1

Views: 1125

Answers (1)

Tanaike
Tanaike

Reputation: 201713

When I saw the image of the HTML, it seems that the value you want is put in the tag of div. So how about the following modification?

Modified formula:

=IMPORTXML(A1,"//div[@class='quote__close']")
  • I modified the xpath to //div[@class='quote__close'].

Result:

enter image description here

Reference:

Upvotes: 3

Related Questions