Написах скромно скриптче на PHP за прилагане на XPath изрази през командния ред. Скрипта изисква инсталиран Lynx или, ако се ползва под Windows трябва да се постави Lynx в същата директория. Готиното на това програмче е, че не се интересува дали има грешки в страницата.
| <?php
if ($argc != 3 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>
 
This is a XPath extractor.
 
  REQUIRES:
  "lynx" to be installed!
 
  USAGE:
  <?php echo $argv[0]; ?> <site> <xpath>
 
  EXAMPLE:
  <?php echo $argv[0]; ?> http://site.com/some_page.html "//a[contains(@href,\"?rec\") and not(contains(@href,\"comment\"))]/@href"
  --------------------
 
  With the --help, -help, -h,
  or -? options, you can get this help.
 
<?php
} else {
$site=$argv[1];
function get_cont($url){
$c = `lynx -source $url`;
return $c;
}
$html = get_cont($site);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate($argv[2]);
for ($i = 0; $i < $hrefs->length; $i++) {
	$bb = $hrefs->item($i)->nodeValue;
	print "$bb\n";
}
}
?> | 
<?php
if ($argc != 3 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>
This is a XPath extractor.
  
  REQUIRES:
  "lynx" to be installed!
  USAGE:
  <?php echo $argv[0]; ?> <site> <xpath>
  EXAMPLE:
  <?php echo $argv[0]; ?> http://site.com/some_page.html "//a[contains(@href,\"?rec\") and not(contains(@href,\"comment\"))]/@href"
  --------------------
  With the --help, -help, -h,
  or -? options, you can get this help.
<?php
} else {
$site=$argv[1];
function get_cont($url){
$c = `lynx -source $url`;
return $c;
}
$html = get_cont($site);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate($argv[2]);
for ($i = 0; $i < $hrefs->length; $i++) {
	$bb = $hrefs->item($i)->nodeValue;
	print "$bb\n";
}
}
?>
Начин на употреба:
| php xpath.php site.com/some_page.html "//a[contains(@href,\"?rec\") and not(contains(@href,\"comment\"))]/@href" | 
php xpath.php site.com/some_page.html "//a[contains(@href,\"?rec\") and not(contains(@href,\"comment\"))]/@href"
Остава да успея и да го компилирам :). За сега съм пробвал с Bambalam compiler, Roadsend, phc и още няколко по-незнайни емдера и компилатора, но … дърво от всякъде. Все пак, ако си имате инсталиран php и Lynx си работи идеално.
Lynx за Winblowz може да се ползва от тук: Lynx for Windows
Причината да използвам конзолния браузер Lynx е, че много сайтове използват gzip компресия на страниците, за да се зареждат по-бързо. Така не ми се налага да правя еквилибристики от сорта на:
| wget -O - somesite.com | gunzip -c | 
wget -O - somesite.com | gunzip -c