about find(). search someone out from html tag,it return blank
maoSting opened this issue · 6 comments
maoSting commented
it can't find tag out from html.
$html = '<!DOCTYPE HTML>
<html>
<head>
<title>title</title>
</head>
<body>
<div id="a">
an apple
</div>
</body>
</html>
<div id="b">
body
</div>';
$domTree = \voku\helper\HtmlDomParser::str_get_html($html);
var_dump($domTree->findOne('#a')->text()); // an apple
var_dump($domTree->findOne('#b')->text()); // empty
voku commented
Your HTML is not valid. Please check it: https://validator.w3.org/nu/#textarea
PS: why do you need to add the DIV outside your HTML-tag?
petrospap commented
Hello, I have a similar question (don't want to open new issue)
how to determine if we find something?
i.e
$html = HtmlDomParser::file_get_html('https://example.com');
foreach ($html->find('img#test') as $img) {
if ($img->src) {
echo 'found';
}else{
echo 'NOT found';
}
}
Any idea?
voku commented
petrospap commented
Very helpful, although a simply isset can do the trick :)
BTW very nice work!!!
Thanks!
maoSting commented
when i spider some web sites. some gays wrote html is an suprise...
voku commented
Fixed in version v4.7.20