Php 简单html dom解析器-在属性中查找值
现在,我想从变量$element中提取属性“datadetail”中的值,在这里我用attr“datadetail”存储每个div 查看来源:您可以使用此软件包 然后像这样得到你想要的:Php 简单html dom解析器-在属性中查找值,php,parsing,Php,Parsing,现在,我想从变量$element中提取属性“datadetail”中的值,在这里我用attr“datadetail”存储每个div 查看来源:您可以使用此软件包 然后像这样得到你想要的: $html = file_get_html($url); foreach($html->find('div[data-detail]') as $element ) echo $element 需要“vendor/autoload.php”; 使用phtmlparser\Dom; $dom=新的
$html = file_get_html($url);
foreach($html->find('div[data-detail]') as $element )
echo $element
需要“vendor/autoload.php”;
使用phtmlparser\Dom;
$dom=新的dom;
$dom->loadStr('Hey bro,
:));
$a=$dom->find('a')[0];
echo$a->text;//“单击此处”
并获得如下属性:
$html = file_get_html($url);
foreach($html->find('div[data-detail]') as $element )
echo $element
//假设您是从Composer安装的:
需要“vendor/autoload.php”;
使用phtmlparser\Dom;
$dom=新的dom;
$dom->loadFromFile('tests/data/big.html');
$contents=$dom->find('.content-border');
回声计数($contents);//10
foreach($contents作为$content)
{
//获取类属性
$class=$content->getAttribute('class');
}
您可以这样做:
$html = file_get_html($url);
foreach($html->find('div[data-detail]') as $element )
echo $element