I'm working on some code to "scrape" the rebate amount off an Amazon page. So far my code works, but it seems to abort before finishing. I'm not sure if it's a problem in my code, or a timeout setting in php or apache. I'm running php v4.3.2 and Apache 2.0.48 on Windows.
The code seems to stop in slightly different places each time. I can't figure it out though. Please help! I know that the test conditions are redundant, it's just there for test purposes.
Here is my code: (You should be able to cut and paste it to run it.)
Code: Select all
<?
function get_rebate_amt($asin)
{
echo "ASIN: $asin <br>";
echo "URL:
http://www.amazon.com/exec/obidos/tg/detail/-/$asin/
<br>";
// Get any info on rebates
$rebate_amt = "N/A";
$f =
fopen("http://www.amazon.com/exec/obidos/tg/detail/-/$asin/",
'r');
echo "f: $f <br>";
if($f)
{
//echo "here1 <br>";
$page = "";
while($pre = fread($f,100000))
{
$page = $page.$pre;
}
//echo "here2 <br>";
// Check to see if a rebate is availiable
$rebate_avail = substr_count($page, "Mail-In
Rebates");
if ($rebate_avail) {
//echo "here3 <br>";
// Cut out most usless junk
$temp = ereg("Mail-In Rebates(.*)Price After
Rebates", $page,
$content);
$temp = ereg_replace("<br>", "<br>", $contentї1]);
$temp = ereg("price>(.*)</span>", $temp, $content);
$rebate_amt = ereg_replace("<br>", "<br>",
$contentї1]);
}
}
else {
$rebate_amt = "N/A";
}
//echo "func: Rebate amount: $rebate_amt <br>";
unset($rebate_avail);
unset($temp);
unset($pre);
unset($page);
unset($f);
fclose($f);
return $rebate_amt;
}
$cnt = 0;
while ($cnt < 40) {
echo "cnt: $cnt <br>";
echo date('h:i:s');
echo "<br>";
if ($cnt == 0) $asin = "B00009J5VX";
else if ($cnt == 1) $asin = "B00005AC8J";
else if ($cnt == 2) $asin = "B0000DB4D1";
else if ($cnt == 3) $asin = "B00005U0HU";
else if ($cnt == 4) $asin = "B00006RHOD";
else if ($cnt == 5) $asin = "B00009J5W0";
else if ($cnt == 6) $asin = "B00007KDVI";
else if ($cnt == 7) $asin = "B00006LHJY";
else if ($cnt == 8) $asin = "B00007K3A3";
else if ($cnt == 9) $asin = "B00006RTY7";
else if ($cnt == 10) $asin = "B00009J5VX";
else if ($cnt == 11) $asin = "B00005AC8J";
else if ($cnt == 12) $asin = "B0000DB4D1";
else if ($cnt == 13) $asin = "B00005U0HU";
else if ($cnt == 14) $asin = "B00006RHOD";
else if ($cnt == 15) $asin = "B00009J5W0";
else if ($cnt == 16) $asin = "B00007KDVI";
else if ($cnt == 17) $asin = "B00006LHJY";
else if ($cnt == 18) $asin = "B00007K3A3";
else if ($cnt == 19) $asin = "B00006RTY7";
else if ($cnt == 20) $asin = "B00009J5VX";
else if ($cnt == 21) $asin = "B00005AC8J";
else if ($cnt == 22) $asin = "B0000DB4D1";
else if ($cnt == 23) $asin = "B00005U0HU";
else if ($cnt == 24) $asin = "B00006RHOD";
else if ($cnt == 25) $asin = "B00009J5W0";
else if ($cnt == 26) $asin = "B00007KDVI";
else if ($cnt == 27) $asin = "B00006LHJY";
else if ($cnt == 28) $asin = "B00007K3A3";
else if ($cnt == 29) $asin = "B00006RTY7";
else if ($cnt == 30) $asin = "B00009J5VX";
else if ($cnt == 31) $asin = "B00005AC8J";
else if ($cnt == 32) $asin = "B0000DB4D1";
else if ($cnt == 33) $asin = "B00005U0HU";
else if ($cnt == 34) $asin = "B00006RHOD";
else if ($cnt == 35) $asin = "B00009J5W0";
else if ($cnt == 36) $asin = "B00007KDVI";
else if ($cnt == 37) $asin = "B00006LHJY";
else if ($cnt == 38) $asin = "B00007K3A3";
else if ($cnt == 39) $asin = "B00006RTY7";
$rebate_amt = get_rebate_amt($asin);
echo "Rebate Amount: $rebate_amt<br>";
echo "<hr>";
$cnt++;
}
?>Thanks,
Grant