使用该IMPORTXML
功能,是否可以构造一个XPATH查询来获取给定Wikipedia页面的行业值?
例如,我要从此页面提取的值-https: //en.wikipedia.org/wiki/Target_Corporation-是“零售”,而在此页面上提取的值-https: //en.wikipedia.org/wiki/Boohoo。 com-这将是“时尚”。
如果我的理解是正确的,那么和其他模式一样,该xpath的公式又如何呢?请认为这只是几个答案之一。
=IMPORTXML(A1,"//th[text()='Industry']/following-sibling::td")
//th[text()='Industry']/following-sibling::td
。https://en.wikipedia.org/wiki/Target_Corporation
或https://en.wikipedia.org/wiki/Boohoo.com
放在单元格“ A1”中。从您的回复中,我知道您想再添加2个URL。因此,所有URL如下。
https://en.wikipedia.org/wiki/Target_Corporation
对于上述的URL,当式=IMPORTXML(A1,"//th[text()='Industry']/following-sibling::td")
被使用,Retail
,Fashion
,Retail
和Travel, services
被返回。
当XPath是修改为//th[text()='Industry']/following-sibling::td/a
,Retail
,#N/A
,#N/A
和Travel
返回。
其原因是由于以下差异。
<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>
通过这种方式,我觉得遗憾的是,为了取回Travel
,Retail
并Fashion
从上面,那些不能直接与只有一个XPath的检索。因此,在这种情况下,我使用了内置函数。
在这种解决方法中,我使用了INDEX
。请认为这只是几个答案之一。
=INDEX(IMPORTXML(A1,"//th[text()='Industry']/following-sibling::td"),1,1)
//th[text()='Industry']/following-sibling::td
。这没有修改。INDEX
。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句