drzablspw01655860 2011-01-26 05:24
浏览 85

在div id = footer中找不到<p>

A question related on my previous post, about Simple HTML DOM Parser. This is my html code:

<div id="header">
<h1>Hello World!</h1>
</div>
<div id="container">
 <div id="content">
    <p> </p>
    </div>
</div>

<div id="footer">
<p>LINK HERE</p>
</div>

I want to insert a link on the <p> of the footer.I could insert a link but the problem is, if there is another <p> before the div footer's <p>, the link will be inserted at the <p> in the html code. It's like it can't identify or it cannot be detected that it SHOULD ONLY SEARCH IN THE div id=footer, not the whole html code.

Here's what i've got:

foreach($html->find('div#footer') as $footer) 
   {
    foreach($footer->find('p') as $p) 
   {
  $footerInnerText = $p->find('p', 0)->innertext;
  $theLink = '<a href="index.php" title="" rel="home">'. $footerInnerText. '</a>';
  $html->find('p', 0)->innertext = "
" .$theLink."
";
  }

I have also tried this:

$e = $html->find('div#footer', 0)->find('p', 0);

What am i missing here?

  • 写回答

1条回答 默认 最新

  • dongye8110 2011-02-23 10:29
    关注

    I find Nodes in HTML a bit funky. I've seen a fair few problems with blank nodes, etc. For example in HTML the blank " " would parse as nothing, as you do not have any real text in it.

    &nbsp; is the code you need for a space.

    I believe the problem may be caused by the innerHTML of the P being blanked, therefore not existing. Have you tried by putting any values in it at all, just a random test line or the like?

    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥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的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比