diff --git a/bridges/AmazonBridge.php b/bridges/AmazonBridge.php
index 25c061f7..235662a7 100644
--- a/bridges/AmazonBridge.php
+++ b/bridges/AmazonBridge.php
@@ -49,6 +49,48 @@ class AmazonBridge extends BridgeAbstract {
),
));
+ public function collectData() {
+
+ $baseUrl = sprintf('https://www.amazon.%s', $this->getInput('tld'));
+
+ $url = sprintf(
+ '%s/s/?field-keywords=%s&sort=%s',
+ $baseUrl,
+ urlencode($this->getInput('q')),
+ $this->getInput('sort')
+ );
+
+ $dom = getSimpleHTMLDOM($url);
+
+ $elements = $dom->find('div.s-result-item');
+
+ foreach($elements as $element) {
+ $item = [];
+
+ $title = $element->find('h2', 0);
+ if (!$title) {
+ continue;
+ }
+
+ $item['title'] = $title->innertext;
+
+ $itemUrl = $element->find('a', 0)->href;
+ $item['uri'] = urljoin($baseUrl, $itemUrl);
+
+ $image = $element->find('img', 0);
+ if ($image) {
+ $item['content'] = ' . ')
';
+ }
+
+ $price = $element->find('span.a-price > .a-offscreen', 0);
+ if ($price) {
+ $item['content'] .= $price->innertext;
+ }
+
+ $this->items[] = $item;
+ }
+ }
+
public function getName(){
if(!is_null($this->getInput('tld')) && !is_null($this->getInput('q'))) {
return 'Amazon.' . $this->getInput('tld') . ': ' . $this->getInput('q');
@@ -56,40 +98,4 @@ class AmazonBridge extends BridgeAbstract {
return parent::getName();
}
-
- public function collectData() {
-
- $uri = 'https://www.amazon.' . $this->getInput('tld') . '/';
- $uri .= 's/?field-keywords=' . urlencode($this->getInput('q')) . '&sort=' . $this->getInput('sort');
-
- $html = getSimpleHTMLDOM($uri);
-
- foreach($html->find('li.s-result-item') as $element) {
-
- $item = array();
-
- // Title
- $title = $element->find('h2', 0);
- if (is_null($title)) {
- continue;
- }
-
- $item['title'] = html_entity_decode($title->innertext, ENT_QUOTES);
-
- // Url
- $uri = $title->parent()->getAttribute('href');
- $uri = substr($uri, 0, strrpos($uri, '/'));
-
- $item['uri'] = substr($uri, 0, strrpos($uri, '/'));
-
- // Content
- $image = $element->find('img', 0);
- $price = $element->find('span.s-price', 0);
- $price = ($price) ? $price->innertext : '';
-
- $item['content'] = ' . ')
' . $price;
-
- $this->items[] = $item;
- }
- }
}