gpt4 book ai didi

表上的 PHP DOM-XPath

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

我正在尝试使用...从表中提取数据

   $tags = $xpath->query('//tr[@valign="top"]/td/span[@style="background-color:#cccccc;font-weight:bold;"]');

在一行看起来像...

   <tr valign="top">
<td style="background-color:#cccccc;"><span style="background-color:#cccccc;font-weight:bold;">Some Company</span>

但它不检索数据,它使用 firebug 中的 DOM 检查器工作...使用 xpath...

     $tags = $xpath->query('//tr[@valign="top"]/td/span');

可以工作,但它会提取其他不需要的数据。有什么建议吗?

最佳答案

这些 style 属性是否可能存在一些排序/格式问题?请尝试以下操作:

//tr[@valign="top"]/td/span[contains(@style, 'background-color:#cccccc') and 
contains(@style, 'font-weight:bold')]

您还可以尝试根据单元格的内容进行选择(假设该值是唯一的):

//tr[@valign="top"]/td/span[.='Some Company']

或者(限制较少):

//tr[@valign="top"]/td/span[contains(., 'Some Company')]

关于表上的 PHP DOM-XPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8454442/

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