Sylvester Loh
Sylvester Loh

Reputation: 39

Google Sheet importxml - How to retrieve only the 1st value?

=IFERROR(importxml(B1, "//title/text()"),A1)

I'm using Google Script to input the above into C1 and fill down.

It works fine when there is only 1 title in each result, but returns an error when there are more than 1 :

Error Array result was not expanded because it would overwrite data in C2

How can I limit the result to just the first title tag found, or (probably better) modify the IFERROR to handle this array 'error'?

Upvotes: 3

Views: 5522

Answers (1)

TheMaster
TheMaster

Reputation: 50799

      =IFERROR(importxml(B1, "(//title/text())[1]"),A1)

Or

     =ARRAY_CONSTRAIN(IFERROR(importxml(B1, "//title/text()"),A1),1,1)

Mark this as answer, If it solves your problem.

Upvotes: 3

Related Questions