0

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.

2

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.

0

The problem is that the page is not a valid XHTML. You can check this by using the W3C Markup Validator Service.

This is a problem because IMPORTXML requires that the tags follow the XML markup rules in order to work for specific nodes. The alternative is to import the source code of the page and then use other spreadsheet functions to parse the required data.

One way was already included in the answer by Tanaike. It works because the body tag markup was properly applied according to the XML markup rules.

Related Q&A

0

The reason is that your xpath is far too complicated - in this case there is only one h4 tag on that website - so you can simplify the path to just a simple //h4 - added this to your test sheet so you can see the live result - note that the value has changed to 3.15 since the time you first posted

enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.