Home > Back-end >  Import numerical value from a website to Google Sheets
Import numerical value from a website to Google Sheets

Time:03-01

I want to import a numerical value from enter image description here

CodePudding user response:

In your situation, how about the following sample formula?

Sample formula:

=IMPORTXML(A1,"//div[@data-name='REG']//div[div[@class='stats_label']/text()='LDCP']/div[@class='stats_value']")
  • In this case, the URL of https://dps.psx.com.pk/company/SYS is put in the cell "A1".

  • When you want to put the value to the cell "B2", please put =IMPORTXML("https://dps.psx.com.pk/company/SYS","//div[@data-name='REG']//div[div[@class='stats_label']/text()='LDCP']/div[@class='stats_value']") to the cell "B2".

  • I thought that in this case, the following formula can be also used.

      =IMPORTXML(A1,"//div[@data-name='REG']//div[@class='stats_value'][../div[@class='stats_label']/text()='LDCP']")
    

Result:

enter image description here

Note:

  • The XPath of this sample formula is for your URL of https://dps.psx.com.pk/company/SYS. So, when you changed the URL, the XPath might not be able to be used. So please be careful about this.

CodePudding user response:

You can use

=REGEXEXTRACT(INDEX(IMPORTXML(A1,"//div[@data-name='REG']"),2,4),"LDCP(\d \.\d )")

enter image description here

assuming that =TRANSPOSE(IMPORTXML(A1,"//div[@data-name='REG']")) will give you these informations enter image description here

By index I fetch the cell I need, then I apply a simple regexextract formula.

This way you can easily retrieve other information.

  • Related