如何优化IMPORTXML函数结果?解决魔兽角色等级重复返回问题
Got it, let's break down why you're seeing the number 36 twice and how to get it to show only once in a single cell.
Why the Duplicate Happens
Your IMPORTXML formula is pulling every element on that character page with the class GameIcon-level. It turns out there are two elements matching that selector on the page—so the formula returns both values, spilling into the current cell and the one below it.
Quick Fixes to Get a Single Value
Here are two simple ways to force the formula to only return the first matching value:
Use
INDEXto grab the first result
Wrap your existingIMPORTXMLformula withINDEX, specifying you want the 1st item in the returned array:=INDEX(IMPORTXML("https://worldofwarcraft.com/en-gb/character/Zenedar/Father","//*[@class='GameIcon-level']"), 1)This tells Sheets to only pull the first value from the list of matches, so it stays in one cell.
Use
ARRAY_CONSTRAINto limit results
Another option is to constrain the output to just 1 row and 1 column:=ARRAY_CONSTRAIN(IMPORTXML("https://worldofwarcraft.com/en-gb/character/Zenedar/Father","//*[@class='GameIcon-level']"), 1, 1)This works similarly—it restricts the array returned by
IMPORTXMLto a single cell-sized range.
Either of these should fix the duplicate issue and show just "36" in your target cell.
内容的提问来源于stack exchange,提问作者Joshua Lines

