function price_book($book) { global $SELLERS_URL; $best_book_price = 1000; $best_book_ship = 2.99; $best_book_ISBN = ""; $best_book_url = NULL; $best_book_price_amazon = 0; // replace entites quote $book = str_replace("’", "'", $book); $book = urlencode($book); // 0. parse all books from pmba reading list foreach ($SELLERS_URL as $seller_url) { // 1. Parse all sellers and save best price + url $seller_price = price_book_sellers($seller_url, $book); if (isset($seller_price)) { $price = $seller_price[0]; $url = $seller_price[1]; // test best price if ($price < $best_book_price) { $best_book_price = $price; $best_book_url = $url; } } } // 2. from best book price url, get price, ship price, ISBN if (!isset($best_book_url)) { return; } $ISBN = get_ISBN($best_book_url); $best_book_price_amazon = get_amazon_price($book); return array($best_book_price_amazon, $best_book_price, $best_book_ship, $best_book_ISBN, $best_book_url); }
function price_book($book) { $amazon_url = "http://www.amazon.fr/gp/search/ref=sr_adv_b/?search-alias=stripbooks&__mk_fr_FR=%C5M%C5Z%D5%D1&unfiltered=1&field-author=&field-title=&field-isbn=&field-publisher=&field-collection=&node=&field-binding_browse-bin=492481011&field-dateop=&field-datemod=&field-dateyear=&sort=relevancerank&Adv-Srch-Books-Submit.x=0&Adv-Srch-Books-Submit.y=0"; $amazon_url .= "&field-keywords=" . $book; $snoopy = new Snoopy(); $snoopy->fetch($amazon_url); $html = $snoopy->results; $html = str_get_html($html); $prices = null; $results = $html->find('#atfResults', 0); if (isset($results)) { // book url $book_url = $results->find('.productTitle', 0); $book_url = $book_url->find('a', 0)->href; $ISBN = get_ISBN($book_url); $prices = get_best_price($ISBN); } else { $prices[0] = 0; $prices[1] = 0; $ISBN = -1; $book_url = 'http://www.amazon.fr'; } $html->clear(); unset($html); return array($prices[0], $prices[1], '2.99', $ISBN, $book_url); }
$array[$i]['name'] = $name; $array[$i]['link'] = $baseurl . $link; $array[$i]['old-price'] = 'N/A'; $array[$i]['new-price'] = text_prepare(pq($item)->find('span[id^="itemPrice_"]')->html()); $array[$i]['date-added'] = text_prepare(str_replace('Added', '', pq($item)->find('div[id^="itemAction_"] .a-size-small')->html())); $array[$i]['priority'] = text_prepare(pq($item)->find('span[id^="itemPriorityLabel_"]')->html()); $array[$i]['rating'] = 'N/A'; $array[$i]['total-ratings'] = $total_ratings; $array[$i]['comment'] = text_prepare(pq($item)->find('span[id^="itemComment_"]')->html()); $array[$i]['picture'] = pq($item)->find('div[id^="itemImage_"] img')->attr('src'); $array[$i]['page'] = $page_num; $array[$i]['ASIN'] = get_ASIN($array[$i]['link']); $array[$i]['large-ssl-image'] = get_large_ssl_image($array[$i]['picture']); $array[$i]['affiliate-url'] = get_affiliate_link($array[$i]['ASIN']); if ($_GET['isbn'] == true) { $array[$i]['isbn'] = get_ISBN($array[$i]['link']); } if ($_GET['author'] == true) { $array[$i]['author'] = pq($item)->find('div[id^="itemInfo_"] .a-row.a-size-small:has(h5 a[id^="itemName_"])'); $array[$i]['author']->find('h5')->remove(); $array[$i]['author'] = trim(preg_replace('/\\([\\ \\w]+\\)/', '', str_replace('by', '', $array[$i]['author']->text()))); } $i++; } } } } } } //go to product details page for isbn function get_ISBN($url)