[英]extract html inside <p class=" without simplehtmldom
我想提取<p class="js-swt-text"
內的html而沒有simplehtmldom
下面是我用simplehtmldom做的工作示例:
<?php
include('simple_html_dom.php');
$html = file_get_html("http://blabla.com");
foreach($html->find('.js-swt-text') as $ret) {
echo $ret;
}
?>
請幫我做domdocument
<?php
$html = file_get_contents("http://blabla.com");
並從每個<p class="js-swt-text"
回顯html
您可以使用:
$html = file_get_contents("http://blabla.com");
$dom = new DomDocument();
$dom->loadHtml($html);
$xpath = new DomXpath($dom);
$items = $xpath->query('//p[@class="js-swt-text"]');
foreach ($items as $item) {
echo $item->textContent . "\n";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.