seredniy
8/2/2016 - 12:05 PM

Парсинг страницы с помощью XPATH

Парсинг страницы с помощью XPATH

/* Use internal libxml errors -- turn on in production, off for debugging */
libxml_use_internal_errors(true);
/* Createa a new DomDocument object */
$dom = new DomDocument;
/* Load the HTML */
$dom->loadHTMLFile("http://google.com");
/* Create a new XPath object */
$xpath = new DomXPath($dom);

/* Set HTTP response header to plain text for debugging output */
header("Content-type: text/plain");

// Получим все названия
$titles = $xpath->query(".//*[@id='block-views-catalog-tovarov-block-1']/div/div/div/div/div/h3");

// Выведем все названия
// foreach ($titles as $i => $node) {
//     echo "Node($i): ", $node->nodeValue, "\n";
// }