Google表格中的IMPORTXML函数

zgall1

使用该IMPORTXML功能,是否可以构造一个XPATH查询来获取给定Wikipedia页面的行业值?

例如,我要从此页面提取的值-https: //en.wikipedia.org/wiki/Target_Corporation-是“零售”,而在此页面上提取的值-https: //en.wikipedia.org/wiki/Boohoo。 com-这将是“时尚”。

Tanaike
  • 您想要创建xpath来检索给定Wikipedia页面的Industry值。

如果我的理解是正确的,那么和其他模式一样,该xpath的公式又如何呢?请认为这只是几个答案之一。

样本公式:

=IMPORTXML(A1,"//th[text()='Industry']/following-sibling::td")
  • xpath是//th[text()='Industry']/following-sibling::td
  • 在这种情况下,URLhttps://en.wikipedia.org/wiki/Target_Corporationhttps://en.wikipedia.org/wiki/Boohoo.com放在单元格“ A1”中。

结果:

在此处输入图片说明

参考:

添加:

从您的回复中,我知道您想再添加2个URL。因此,所有URL如下。

问题和解决方法:

对于上述的URL,当式=IMPORTXML(A1,"//th[text()='Industry']/following-sibling::td")被使用,RetailFashionRetailTravel, services被返回。

当XPath是修改为//th[text()='Industry']/following-sibling::td/aRetail#N/A#N/ATravel返回。

其原因是由于以下差异。

<tr>
  <th scope="row">Industry</th>
  <td class="category"><a href="/wiki/Travel" title="Travel">Travel</a> services</td>
</tr>

<tr>
  <th scope="row" style="padding-right:0.5em;">Industry</th>
  <td class="category" style="line-height:1.35em;"><a href="/wiki/Retail" title="Retail">Retail</a></td>
</tr>

<tr>
  <th scope="row" style="padding-right:0.5em;">Industry</th>
  <td class="category" style="line-height:1.35em;">Fashion</td>
</tr>

通过这种方式,我觉得遗憾的是,为了取回TravelRetailFashion从上面,那些不能直接与只有一个XPath的检索。因此,在这种情况下,我使用了内置函数。

解决方法:

在这种解决方法中,我使用了INDEX请认为这只是几个答案之一。

=INDEX(IMPORTXML(A1,"//th[text()='Industry']/following-sibling::td"),1,1)
  • xpath是//th[text()='Industry']/following-sibling::td这没有修改。
  • 在这种情况下,URL放在单元格“ A1”中。
  • 当检索到两个值时,将检索第一个。由此,我使用了INDEX
结果:

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章