diff --git a/bridges/AmazonPriceTrackerBridge.php b/bridges/AmazonPriceTrackerBridge.php index 1d8959a2..4efd441c 100644 --- a/bridges/AmazonPriceTrackerBridge.php +++ b/bridges/AmazonPriceTrackerBridge.php @@ -40,6 +40,15 @@ class AmazonPriceTrackerBridge extends BridgeAbstract { ), )); + const PRICE_SELECTORS = array( + '#priceblock_ourprice', + '.priceBlockBuyingPriceString', + '#newBuyBoxPrice', + '#tp_price_block_total_price_ww', + 'span.offer-price', + '.a-color-price', + ); + protected $title; /** @@ -54,7 +63,7 @@ class AmazonPriceTrackerBridge extends BridgeAbstract { */ public function getURI() { if (!is_null($this->getInput('asin'))) { - return $this->getDomainName() . '/dp/' . $this->getInput('asin') . '/'; + return $this->getDomainName() . '/dp/' . $this->getInput('asin'); } return parent::getURI(); } @@ -146,13 +155,25 @@ EOT; } private function scrapePriceGeneric($html) { - $priceDiv = $html->find('span.offer-price', 0) ?: $html->find('.a-color-price', 0); + $priceDiv = null; + + foreach(self::PRICE_SELECTORS as $sel) { + $priceDiv = $html->find($sel, 0); + if ($priceDiv) { + break; + } + } + + if (!$priceDiv) { + return false; + } + $priceString = $priceDiv->plaintext; preg_match('/[\d.,]+/', $priceString, $matches); $price = $matches[0]; - $currency = trim(str_replace($price, '', $priceString)); + $currency = trim(str_replace($price, '', $priceString), " \t\n\r\0\x0B\xC2\xA0"); if ($price != null && $currency != null) { return array( @@ -180,6 +201,8 @@ EOT; 'title' => $this->title, 'uri' => $this->getURI(), 'content' => "$imageTag
Price: {$data['price']} {$data['currency']}", + // This is to ensure that feed readers notice the price change + 'uid' => md5($data['price']) ); if ($data['shipping'] !== '0') {