duane2364 2011-01-31 13:17
浏览 17
已采纳

如何使用php定期获取2ed和3rd` <div class =“partright”>`?

There have some texts, how to use php regular get the 2ed and 3rd <div class="partright">? Thanks.

<div class="wrap">
  <div class="content>
    <div class="partleft">
    text1
    </div>
    <div class="partright">
    text2
    </div>
  </div>
  <div class="content>
    <div class="partleft">
    text3
    </div>
    <div class="partright">
    text4
    </div>
  </div>
  <div class="content>
    <div class="partleft">
    text5
    </div>
    <div class="partright">
    text6
    </div>
  </div>
</div>

I want output

<div class="partright">
text4
</div>
<div class="partright">
text6
</div>
  • 写回答

3条回答 默认 最新

  • dpp42324 2011-01-31 13:39
    关注

    Your question is very incomplete but I assume your talking about traversing the elements to modify them in some way.

    You should look at the following library called SimpleDOM

    And usage would be like:

    require_once 'simple_dom.class.php';
    
    $html = "<html_data_here>";
    $html = str_get_html($html);
    
    foreach($html->find(".partleft:nth(2),.partleft:nth(3)") as $p)
    {
        echo $p->outerText;
    }
    

    Note: The above is an example and may not work as expected, for working examples please see the Simple Dom site linked above.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答