首页 > 解决方案 > =IMPORTXML 不导入预期的内容

问题描述

我正在尝试将部门和行业标签导入谷歌文档。

我在用...

=IMPORTXML("https://finance.yahoo.com/quote/ABT/profile?p=ABT","//span[@data-reactid='21']")

在三个不同的单元格中显示:

Profile
Healthcare
About Our Ads

但我想要的只是一个细胞中的医疗保健

=IMPORTXML("https://finance.yahoo.com/quote/ABT/profile?p=ABT","//span[@data-reactid='25']")

在三个不同的单元格中显示:

Financials 
Medical Devices 
Sitemap

但我想要的只是一个单元中的医疗设备

我的语法有什么问题?

标签: google-sheets-formulagoogle-sheets-importxml

解决方案


我认为您也得到了另外两个spans - 因此是三行而不是一排。

您可能想要使用更精确的 xpath,例如:

=IMPORTXML(
  "https://finance.yahoo.com/quote/ABT/profile?p=ABT",
    "//p/span[text()='Sector']/following-sibling::span[1]/text()")

=IMPORTXML(
  "https://finance.yahoo.com/quote/ABT/profile?p=ABT",
    "//p/span[text()='Industry']/following-sibling::span[1]/text()")

在此处输入图像描述


推荐阅读