Skip to content

Commit ced9e56

Browse files
authored
[KleinanzeigenBridge] fix errors when <a> element is not found (#4820)
Sometimes a 'span' is present in place of 'a' in the content, which would cause the bridge to fail. - Use defaultLinkTo() facility instead of adding host domain name to URL manually. - Also use $this->getURI() in place of self::URI.
1 parent d4b3a77 commit ced9e56

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

bridges/KleinanzeigenBridge.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ public function collectData()
9090
{
9191
if ($this->queriedContext === 'By profile') {
9292
for ($i = 1; $i <= $this->getInput('pages'); $i++) {
93-
$html = getSimpleHTMLDOM(self::URI . '/s-bestandsliste.html?userId=' . $this->getInput('userid') . '&pageNum=' . $i . '&sortingField=SORTING_DATE');
93+
$html = getSimpleHTMLDOM($this->getURI() . '/s-bestandsliste.html?userId=' . $this->getInput('userid') . '&pageNum=' . $i . '&sortingField=SORTING_DATE');
94+
$html = defaultLinkTo($html, $this->getURI());
9495

9596
$foundItem = false;
9697
foreach ($html->find('article.aditem') as $element) {
@@ -106,7 +107,7 @@ public function collectData()
106107
if ($this->queriedContext === 'By search') {
107108
$categoryId = $this->findCategoryId();
108109
for ($page = 1; $page <= $this->getInput('pages'); $page++) {
109-
$searchUrl = self::URI . '/s-suchanfrage.html?' . http_build_query([
110+
$searchUrl = $this->getURI() . '/s-suchanfrage.html?' . http_build_query([
110111
'keywords' => $this->getInput('query'),
111112
'locationStr' => $this->getInput('location'),
112113
'locationId' => '',
@@ -119,6 +120,7 @@ public function collectData()
119120
]);
120121

121122
$html = getSimpleHTMLDOM($searchUrl);
123+
$html = defaultLinkTo($html, $this->getURI());
122124

123125
// end of list if returned page is not the expected one
124126
if ($html->find('.pagination-current', 0)->plaintext != $page) {
@@ -137,7 +139,7 @@ private function addItem($element)
137139
$item = [];
138140

139141
$item['uid'] = $element->getAttribute('data-adid');
140-
$item['uri'] = self::URI . $element->getAttribute('data-href');
142+
$item['uri'] = $element->getAttribute('data-href');
141143

142144
$item['title'] = $element->find('h2', 0)->plaintext;
143145
$item['timestamp'] = $element->find('div.aditem-main--top--right', 0)->plaintext;
@@ -150,18 +152,16 @@ private function addItem($element)
150152
$element->find('img', 0) ? $element->find('img', 0)->getAttribute('src') : ''
151153
)
152154
); //enhance img quality
153-
$textContainer = $element->find('div.aditem-main', 0);
154-
$textContainer->find('a', 0)->href = self::URI . $textContainer->find('a', 0)->href; // add domain to url
155-
$item['content'] = '<img src="' . $imgUrl . '"/>' .
156-
$textContainer->outertext;
155+
156+
$item['content'] = '<img src="' . $imgUrl . '"/>' . $element->find('div.aditem-main', 0)->outertext;
157157

158158
$this->items[] = $item;
159159
}
160160

161161
private function findCategoryId()
162162
{
163163
if ($this->getInput('category')) {
164-
$html = getSimpleHTMLDOM(self::URI . '/s-kategorie-baum.html');
164+
$html = getSimpleHTMLDOM($this->getURI() . '/s-kategorie-baum.html');
165165
foreach ($html->find('a[data-val]') as $element) {
166166
$catId = (int)$element->getAttribute('data-val');
167167
$catName = $element->plaintext;

0 commit comments

Comments
 (0)