示例#1
0
                return $Amazon;
            }
            // Else
        }
        // Else
    } else {
        if ($RequestType == "ItemSearch") {
            $pxml = aws_signed_request("com", array("Operation" => "ItemSearch", "SearchIndex" => "Books", "Keywords" => "{$SearchPhrase}", "ResponseGroup" => "Large"), $public_key, $private_key);
            if ($pxml === False) {
                return false;
                // Problem in accessing AMAZON API
            } else {
                if ($pxml->Items->Item->ItemAttributes->ListPrice->FormattedPrice == "") {
                    return false;
                } else {
                    $Amazon['AmazonListPrice'] = $pxml->Items->Item->ItemAttributes->ListPrice->FormattedPrice;
                    $Amazon['NonAmazonNewPrice'] = $pxml->Items->Item->OfferSummary->LowestNewPrice->FormattedPrice;
                    $Amazon['NonAmazonUsedPrice'] = $pxml->Items->Item->OfferSummary->LowestUsedPrice->FormattedPrice;
                    $Amazon['AmazonDiscountPrice'] = $pxml->Items->Item->Offers->Offer->OfferListing->Price->FormattedPrice;
                    $Amazon['AmazonDetailPageURL'] = $pxml->Items->Item->DetailPageURL;
                    return $Amazon;
                }
                // Else
            }
            // Else
        }
    }
}
//$am =  getAmazonData("Guide to Presentations,  Munter, 2nd","ItemSearch");
$am = getAmazonData("9780077219857", "ItemLookup");
var_dump($am);
示例#2
0
function MainBookData($url, $initial_csv_row_data, &$output)
{
    include_once "library/simple_html_dom.php";
    $Main_Data = "";
    $html = file_get_dom($url);
    $ul = $html->find('div[id=material_results] ul');
    // Header for csv
    // CHeck whether Material Exists
    if ($ul != null) {
        $total_type_books = count($ul);
        // Counting type of books
        for ($j = 0; $j < $total_type_books; $j++) {
            $all_li = $ul[$j]->find('li');
            $total_books = count($all_li);
            //This will give us Amount of books
            for ($i = 0; $i < $total_books; $i++) {
                $BookTitle = $all_li[$i]->find('span[class=wrap]', 0)->plaintext;
                $BookTitle = htmlspecialchars_decode($BookTitle);
                $ImageUrl = $all_li[$i]->find('img', 0)->getAttribute("src");
                if ($all_li[$i]->find('div[class=field]', 1)->plaintext != "") {
                    $BK_UsedPrice = $all_li[$i]->find('div[class=field]', 1)->find('span[class=emph]', 0)->plaintext;
                }
                if ($all_li[$i]->find('div[class=field]', 2)->plaintext != "") {
                    $BK_NewPrice = $all_li[$i]->find('div[class=field]', 2)->find('span[class=emph]', 0)->plaintext;
                }
                if ($all_li[$i]->find('div[id=field]', 0)->plaintext != "") {
                    $BK_DigitalPrice = $all_li[$i]->find('div[id=field]', 0)->find('span[class=emph]', 0)->plaintext;
                }
                $AuthorEdition = $all_li[$i]->find('div[class=detail]', 0)->plaintext;
                $AuthorEdition = split("Edition", $AuthorEdition);
                // Data Cleaning for Author and Edition
                $Author = $AuthorEdition[0];
                $Edition = $AuthorEdition[1];
                $Author = str_replace("Author:", "", $Author);
                $Edition = str_replace(":", "", $Edition);
                $Author = str_replace("\n", "", $Author);
                $Edition = str_replace("\n", "", $Edition);
                $Author = ltrim($Author);
                $Edition = ltrim($Edition);
                $Author = rtrim($Author);
                $Author = htmlspecialchars_decode($Author);
                $Edition = rtrim($Edition);
                // --- Data Cleaning ENDz
                $SisterUrl_Ancher = $all_li[$i]->find('div[id=field] a', 0);
                if ($SisterUrl_Ancher->plaintext != "") {
                    // Check if Sister URL is available
                    $SisterUrl = $SisterUrl_Ancher->getAttribute("href");
                    $sister_site_data = SisterSiteData($SisterUrl);
                } else {
                    $sister_site_data = ",,,,,,";
                }
                if ($ImageUrl != "http://images.efollett.com/books/noBookImage.gif") {
                    // ONly Access Amazon Api if you image FOund
                    if ($ImageUrl != "http://images.efollett.com/booksnull") {
                        $amazon = getAmazonData("{$BookTitle}, {$Author}, {$Edition}");
                        if ($amazon) {
                            $AmazonListPrice = $amazon['AmazonListPrice'];
                            $AmazonDiscountPrice = $amazon['AmazonDiscountPrice'];
                            $NonAmazonNewPrice = $amazon['NonAmazonNewPrice'];
                            $NonAmazonUsedPrice = $amazon['NonAmazonUsedPrice'];
                            $AmazonDetailPageURL = $amazon['AmazonDetailPageURL'];
                        }
                        $Bk_ISBN = split("/", $ImageUrl);
                        $Bk_ISBN_count = count($Bk_ISBN) - 1;
                        $Bk_ISBN = $Bk_ISBN[$Bk_ISBN_count];
                        $Bk_ISBN = explode('.', $Bk_ISBN);
                        $Bk_ISBN = $Bk_ISBN[0];
                    }
                }
                echo $row_data = "{$initial_csv_row_data},\"{$BookTitle}\",\"{$Author}\",\"{$Edition}\",{$ImageUrl},{$BK_UsedPrice},{$BK_NewPrice},{$BK_DigitalPrice},{$Bk_ISBN},{$AmazonListPrice},{$AmazonDiscountPrice},{$NonAmazonNewPrice},{$NonAmazonUsedPrice},{$AmazonDetailPageURL},{$SisterUrl},{$sister_site_data}\n";
                echo "\n";
                fwrite($output, $row_data);
                // Clearing Space
                unset($BookTitle);
                unset($SisterUrl);
                unset($Author);
                unset($Edition);
                unset($ImageUrl);
                unset($BK_UsedPrice);
                unset($BK_NewPrice);
                unset($BK_DigitalPrice);
                unset($Bk_ISBN);
                unset($row_data);
                unset($amazon);
                unset($AmazonListPrice);
                unset($NonAmazonNewPrice);
                unset($NonAmazonUsedPrice);
                unset($AmazonDiscountPrice);
                unset($AmazonDetailPageURL);
            }
            // for
        }
    } else {
        // If no book is found still add the record
        echo $row_data = "{$initial_csv_row_data},,,,,,,,\n";
        fwrite($output, $row_data);
    }
    $html->__destruct();
    unset($html);
    unset($ul);
}