dragam0217 2011-11-22 22:40
浏览 45

在PHP Simple HTML DOM Library中使用next_sibling()?

I have a table of data, I want to capture the text inside of the element that immediately follows a element that has a label inside with a title attribute of "label". See the table here:

<table>
<tr>
    <th><label title="Country">Country</label></th>
    <td>I want to capture this text</td>
</tr>
<tr>
    <th><label title="Other">Heading I don't need</label></th>
    <td>Cell I don't Need</td>
</tr>
</table>

The only identifiable characteristic I can find is that the td is preceded by a th that has a label inside that has a unique title attribute.

First, I tried it without the label since I know it's going to be the first result for:

$found = $html->find('tr th')->next_sibling();
echo($found[0]);

But that doesn't appear to be the correct usage of next sibling. Can somebody tell me how to correctly use it to get the element that follows a element? Even better if there is someway to incorporate that label with its unique title attribute.

  • 写回答

1条回答 默认 最新

  • doukuanyong1939 2012-10-09 06:45
    关注

    Can somebody tell me how to correctly use it to get the element that follows a element?

    Next sibling does not return its content. Instead u should use first_child().

    Even better if there is someway to incorporate that label with its unique title attribute.

    What do you mean 'to incorporate' ? You can use find() to get contents of every label nevertheless it has title or not. If you want to get content of a label with specified title then you should mention your title in find(). I suggest you to read the manual: http://simplehtmldom.sourceforge.net/manual.htm

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序