【问题标题】:concatenate div into scraped content将 div 连接到抓取的内容中
【发布时间】:2021-02-01 02:40:54
【问题描述】:

我正在使用 PHP 简单的 dom 解析器,我应该如何在其中插入额外的实体?像 $html 包含

<table class="tb">..</table>
<table>..</table>
<table>..</table>

我知道如何选择dom,比如$html-&gt;find('div[class="tb"][1]'); 但是如何在它之后连接新的div?就像我想把广告 btw 表。

【问题讨论】:

    标签: php domparser simpledom


    【解决方案1】:

    如果你还想要简单的例子:

    $banner = '<div class="ads">blablabla</div>';
    $tables = $html->find('table');
    foreach($tables as $table){
        $table->outertext .= $banner;
    }
    

    或者:

    $html->find('div[class="tb"][1]').outertext .= '<div class="ads">blablabla</div>';
    

    在阅读 here 的文档后制作的 (:

    【讨论】:

      猜你喜欢
      • 2015-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多