Google-sheets – How to match XPath for Sheets IMPORTXML formula

google sheetsimportxml

New with IMPORTXML, and having trouble matching the XPath on my URL

The URL is https://phlanx.com/engagement-calculator?insta=accelerateokanagan

The value I am trying to extract is the orange 4.4% on the page.

So far I have tried:

Using the XPath Finder Firefox Add-on, which gave me an XPath of /html/body/div[2]/div[1]/div[1]/article/div/div/div/div/div/div[3]/h4

But I got this error:

Error Imported content is empty.

My total formula is:

=IMPORTXML("https://phlanx.com/engagement-calculator?insta=accelerateokanagan","/html/body/div[2]/div[1]/div[1]/article/div/div/div/div/div/div[3]/h4")

I have set up a test spreadsheet here.

Best Answer

In my environment, values from tags couldn't be retrieved. If your situation is the same with me, for example, how about this? Please think of this as one of several answers. https://phlanx.com/engagement-calculator?insta=accelerateokanagan is put in a cell "A1".

=INDEX(ARRAYFORMULA(REGEXEXTRACT(IMPORTXML(A1, "//body"),"@accelerateokanagan ENGAGEMENT RATE (\d.+%)")), 1, 6)

If you want only the number, please use this.

=INDEX(ARRAYFORMULA(REGEXEXTRACT(IMPORTXML(A1, "//body"),"@accelerateokanagan ENGAGEMENT RATE (\d.+)%")), 1, 6)

Result :

enter image description here

If this was not useful for you, I'm sorry.