download12749 2012-06-12 22:10
浏览 29
已采纳

从另一页的div中拉取并嵌入代码

I'm using simple-html-dom to try and pull some code from another site. Here's some simple example code that replicates what I'm trying to accomplish.

<html>
  <body>
    <h1>Title!</h1>
    <div class="sample">
        <div class="another_class">...</div>
        <div class="one_more">
          Some awesome text!
        </div>
    </div>
    <div class="sample">
        <div class="another_class">...</div>
        <div class="one_more">
          Some awesome text!
        </div>
    </div>
    <div class="sample">
        <div class="another_class">...</div>
        <div class="one_more">
          Some awesome text!
        </div>
    </div>
  </body>
</html>

So I'm trying to pull all div sample blocks...including the tags. So basically I want to echo the following code onto my site, tags and all:

    <div class="sample">
        <div class="another_class">...</div>
        <div class="one_more">
          Some awesome text!
        </div>
    </div>
    <div class="sample">
        <div class="another_class">...</div>
        <div class="one_more">
          Some awesome text!
        </div>
    </div>
    <div class="sample">
        <div class="another_class">...</div>
        <div class="one_more">
          Some awesome text!
        </div>
    </div>

I just learned about simple-html-dom today, so I'm still trying to figure it out. Here's what I've gathered so far, which isn't working.

<?php
  include('simplehtmldom_1_5/simple_html_dom.php');
  $page = 'http://www.sampleURL.com';
  $html = file_get_html($page);
  foreach($html->find('div.sample') as $element) 
    echo $element->outertext . '<br />';    
?>
  • 写回答

1条回答 默认 最新

  • dtd5644 2012-06-12 22:58
    关注

    I solved my own problem...I was attempting to pull from the wrong URL >_>

    No wonder it wasn't returning anything! The code I have posted is correct.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊