$html = file_get_contents('https://www.olx.ua/elektronika/tv-videotehnika/odessa/?search%5Bprivate_business%5D=private');
libxml_use_internal_errors(true);
$dom = new \DOMDocument();
$dom->loadHTML($html);
$xpath = new \DOMXPath($dom);
$elements = $xpath->query('/html/body/div[1]/div[4]/section/div[3]/div/div[1]/table[2]/tbody/tr/td/div/table/tbody/tr[1]/td[2]/div/h3/a/strong');
foreach ($elements as $title) {
echo "$title->nodeValue\n";
}
//div[@class="im_dialog_peer"]/span[normalize-space(text()) = 'Telegram']/../..//div[@class="im_dialog_date"]/text()
//Лицевой_счёт/Член_хозяйства/Улица/@idref | //Лицевой_счёт/Член_хозяйства/Субъект/@idref
//Лицевой_счёт[@id="FaceAcc_00vX"]/Член_хозяйства/Улица/@idref
//Лицевой_счёт[@id="FaceAcc_00vX"]/Член_хозяйства/Субъект/@idref
https://ideone.com/55RWwA#li_55RWwA foreach ($xpath->query('//a/@href') as $href) {
echo $href->nodeValue, PHP_EOL;
}
https://3v4l.org/0XlvA $entry = $xpath->query('//div[contains(@id, \'entry\')]/div');
$content = '';
foreach($entry as $element) {
if(! $xpath->evaluate("contains(@class, 'foo')", $element)) {
$content .= $dom->saveHTML($element) . PHP_EOL;
}
}
echo $content;
//<div class="world bar">bla bla bla</div>
//<div class="two bar">bla bla bla</div>
//<div class="paper bar">bla bla bla</div>
//<div class="boo bar loo">bla bla bla</div>
https://3v4l.org/FhNUp foreach ($articles as $article) {
$query = 'div/span[1]/a[1]';
$el = $xpath->evaluate($query, $article);
if( $el->length ) {
echo $dom->saveHTML($el->item(0)), PHP_EOL;
}
}
<root>
<el1>1</el1>
<el2>
<el1>2</el1>
</el2>
</root>
<el1>1</el1>
поскольку он ищет только на один уровень.<el1>1</el1>
и <el1>2</el1>
поскольку ищет на всех уровнях вложенности. $dom = new DOMDocument;
$dom->loadXML('<div>123 <br /> 456</div>');
$xpath = new DOMXPath($dom);
foreach ($xpath->query('//div/text()') as $textNode) {
echo trim($textNode->nodeValue), PHP_EOL;
}
ideone.com/FYkZwX