There is this little script
PHP Code:
<?php
error_reporting(E_ALL);
/*
getmodes.php -- scrapes amazon modes and categories for you
Author: Jason Levitt
Version: 1.03
Date: March 25th, 2004
Web site: [url]http://amazonlib.sourceforge.net[/url]
Getmodes goes to all the amazon sites and scrapes
the current set of modes and categories off of the
home page. It returns them in your choice of a:
1) Convenient PHP associative array structure that you can copy and past into
your PHP programs.
2) Convenient Javascript array structure
3) Well-formed XML
Disclaimer: this program is a screen-scraper and will
likely return incorrect results if Amazon drastically
changes the layout of their home pages.
Copyright (c) 2004 Jason Levitt
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation.
[url]http://www.gnu.org/licenses/gpl.html[/url]
*/
Define('PHPARR', 1); // PHP associative array
Define('JSARR', 2); // Javascript array
Define('XML', 3); // well-formed XML
//===================================
// USER DEFINED SETTINGS
$of=PHPARR; // output format, PHPARR | JSARR | XML
//END USER DEFINED SETTINGS
//===================================
$num=$HTTP_SERVER_VARS['argc'];
$eol=($num > 0) ? "\n" : "";
$urls = array (
'us' => 'http://www.amazon.com',
'uk' => 'http://www.amazon.co.uk',
'de' => 'http://www.amazon.de',
'fr' => 'http://www.amazon.fr',
'ca' => 'http://www.amazon.ca',
'jp' => 'http://www.amazon.co.jp'
);
// The first select tag on the Amazon home page
$selstrings = array(
'us' => '<select name=url>',
'uk' => '<select name="url" size="1">',
'de' => '<select name=url>',
'fr' => '<select name="url">',
'ca' => '<select name="url">',
'jp' => '<select name=url>'
);
if ($of == XML) {
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'."\n";
echo '<amazonmodes>';
}
foreach ($urls as $k => $link) {
$matches=array();
$dataus='';
$stuff=parse_url($link);
$fpus = @fopen($link,"r");
if ($fpus == false) {
die("Unable to open url $link $eol");
}
while($line1=fgets($fpus,4096)) {
$dataus=$dataus.$line1;
}
fclose($fpus);
switch ($of) {
case PHPARR:
echo "$eol $eol // Modes for ".$stuff['host']." $eol";
echo '$Modes'.strtoupper($k).' = array( '.$eol;
break;
case JSARR:
echo $eol.'theOptions["'.$stuff['host'].' ('.strtoupper($k).')"] = ['.$eol;
break;
case XML:
echo "\n".'<modes country="'.$k.'">'."\n";
break;
}
$sel=$selstrings[$k];
$foundname=stristr($dataus, $sel);
if ($foundname)
{
$place=strpos($foundname, '</select>');
$workstr=substr($foundname, strlen($sel), $place-strlen($sel));
$workstr=str_replace("\n", " ", $workstr);
preg_match_all("/<option value=\"(?:index=)?(.*?)\"[^>]*>([^<>]*)/s", $workstr, $matches, PREG_SET_ORDER);
$i=0;
foreach ($matches as $val) {
$i++;
$mode=trim($val[1]);
$what=trim($val[2]);
switch ($of) {
case PHPARR:
if ($i == sizeof($matches)) {
echo "'$mode'".' => '."'$what' $eol";
} else {
echo "'$mode'".' => '."'$what', $eol";
}
break;
case JSARR:
if ($i == sizeof($matches)) {
echo "[\"$what\"".','."\"$mode\"] $eol";
} else {
echo "[\"$what\"".','."\"$mode\"], $eol";
}
break;
case XML:
// Don't want double encoding -- decode first, then encode
$mode=html_entity_decode($mode, ENT_NOQUOTES);
$what=html_entity_decode($what, ENT_NOQUOTES);
echo '<mode name="'.htmlentities($mode, ENT_NOQUOTES).'">'.htmlentities($what, ENT_NOQUOTES).'</mode>'."\n";
break;
}
}
switch ($of) {
case PHPARR:
echo ');';
break;
case JSARR:
echo '];';
break;
case XML:
echo '</modes>';
break;
}
} else {
die("No modes found for site $link $eol");
}
}
if ($of == XML) {
echo "\n".'</amazonmodes>'."\n";
}
?>
__________________
<a href="http://www.bridal-jewellery.co.uk/affiliate_program.htm" target="_blank">Earn 6% commission on Bridal Jewellery</a>
|