这是代码
include('simple_html_dom.php');
// Create DOM from URL
$page = "http://indonesiax.co.id";
$html = new simple_html_dom();
$html->load_file($page);
// Find all Images
$value = $html->find('div p img', 0)->outerhtml;
echo $value;
我想选择这行代码的outerHTML但不会工作
$value = $html->find('div p img', 0)->outerhtml;
如果你们知道如何在HTML DOM Parser中选择outerHTML,请分享。
抓取的示例页面https://indonesiax.co.id/
我想用这样的标签显示输出完整
<img src="https://files.edx.org/openedx-logos/edx-openedx-logo-tag-dark.png" alt="Powered by Open edX" width="140">
答案 0 :(得分:0)
解决。 应该是这样的
include('simple_html_dom.php');
// Create DOM from URL
$page = "http://indonesiax.co.id";
$html = new simple_html_dom();
$html->load_file($page);
// Find all images
$altValue = $html->find('div p img', 0);
echo " src= $altValue->src<br /><br />";
echo " alt= $altValue->alt<br /><br />";
echo " width= $altValue->width<br /><br />";
输出就像
src= https://files.edx.org/openedx-logos/edx-openedx-logo-tag-dark.png
alt= Powered by Open edX
width= 140