gpt4 book ai didi

xpath - Google Spreadsheet XPATH:无法提取没有数据/值的元素

转载 作者:行者123 更新时间:2023-12-03 16:24:06 26 4
gpt4 key购买 nike

从这个link我想获得等级位置符号,我使用以下方法获得图像链接:

=IMPORTXML("https://int.soccerway.com/national/england/premier-league/20172018/regular-season/r41547/tables/","//table[@class='leaguetable sortable table detailed-table']//tr/td[@class='direction']/img/@src")


是的,我得到img网址。

https://s1.swimg.net/gsmf/678/img/delta_plus.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif
https://s1.swimg.net/gsmf/678/img/delta_plus.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif
https://s1.swimg.net/gsmf/678/img/delta_plus.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif


但是如何获取里面没有元素的 <td class="direction"></td>

一些元素具有img标签,如下所示:

<td class="direction"><img src="https://s1.swimg.net/gsmf/678/img/delta_plus.gif" width="7" height="4" title="Previous rank: 4" alt="Previous rank: 4"></td>


另一个元素内部没有img标签:

<td class="direction"></td>


如何获取里面没有数据的元素,所以我可以像这样获取列表:

https://s1.swimg.net/gsmf/678/img/delta_plus.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif



https://s1.swimg.net/gsmf/678/img/delta_plus.gif


https://s1.swimg.net/gsmf/678/img/delta_min.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif

https://s1.swimg.net/gsmf/678/img/delta_plus.gif
https://s1.swimg.net/gsmf/678/img/delta_min.gif


我该怎么办?谢谢

最佳答案

您要同时检索<td class="direction"></td><td class="direction"><img ... /></td>。当td没有<img ... />时,您要放置空白行。如果我的理解是正确的,那么该修改如何? https://int.soccerway.com/national/england/premier-league/20172018/regular-season/r41547/tables/放在“ A1”中。

修改公式:

=IMPORTXML(A1,"//td[@class='direction' and not(*)] | //td[@class='direction']/img/@src")



//td[@class='direction' and not(*)]表示 td是具有 class且没有子元素的 direction
//td[@class='direction']/img/@src表示 td具有 img的子元素,并检索 @src


这样,当 td@class='direction'具有 img的子元素时,将检索 @src。当 td@class='direction'没有子元素时,将放置空白。

结果:

enter image description here

注意 :


您也可以使用 =IMPORTXML(A1,"//table[@class='leaguetable sortable table detailed-table']//tr/td[@class='direction' and not(*)] | //table[@class='leaguetable sortable table detailed-table']//tr/td[@class='direction']/img/@src")


如果我误解了您的问题,对不起。

关于xpath - Google Spreadsheet XPATH:无法提取没有数据/值的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50368840/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com