PHP crawl example

This is a little example how to crawl a web page with PHP, in this example I crawl my own page with XPATH to get all titles.

<?php
# turn erros of
libxml_use_internal_errors(true);
# creat DomDocument Object
$DOM = new DomDocument;
# load the THML
$DOM->loadHTMLFile("/");
# creat DomXPath Object
$XPATH = new DomXPath($DOM);
# get all titles with XPATH
$mynodes = $XPATH->query("//article//header//h1");
# print result
foreach ($mynodes as $i => $mynodes) {
    echo "[$i] => '", $mynodes->nodeValue, "'n";
}
?>

This is our result, this are the matches from the XPATH:

[0] => 'create multiple file in shell with touch'
[1] => 'Format current Date in Perl and Bash'
[2] => 'Perl Print Benchmark'
[3] => 'Perl simple Data Dumper for references'
[4] => 'Arduino C Program LED Blink'
[5] => 'Perl Constant Benchmark'
[6] => 'Benchmark Debug perl'
[7] => 'Programmier-Einleitung in C/C++'
[8] => 'perl debug output'
[9] => 'crontab via script'

To see this in Perl click: Perl crawl example.

One thought on “PHP crawl example”

  1. Useful info. Lucky me I found your site by chance, and I am stunned why this coincidence did not came
    about earlier! I bookmarked it.

Leave a Reply

Your email address will not be published.

nine − three =