From 50c90eb5df69ea140f50068318c3794d0cdf52d5 Mon Sep 17 00:00:00 2001 From: Tobias Alexander Franke Date: Thu, 4 Apr 2019 22:54:08 +0200 Subject: [PATCH] [EconomistBridge] Add new bridge (#1067) * [EconomistBridge] Added new bridge --- bridges/EconomistBridge.php | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 bridges/EconomistBridge.php diff --git a/bridges/EconomistBridge.php b/bridges/EconomistBridge.php new file mode 100644 index 00000000..1256be45 --- /dev/null +++ b/bridges/EconomistBridge.php @@ -0,0 +1,63 @@ +find('article') as $element) { + + $a = $element->find('a', 0); + $href = self::URI . $a->href; + $full = getSimpleHTMLDOMCached($href); + $article = $full->find('article', 0); + + $header = $article->find('h1', 0); + $author = $article->find('span[itemprop="author"]', 0); + $time = $article->find('time[itemprop="dateCreated"]', 0); + $content = $article->find('div[itemprop="description"]', 0); + + // Remove newsletter subscription box + $newsletter = $content->find('div[class="newsletter-form__message"]', 0); + if ($newsletter) + $newsletter->outertext = ''; + + $newsletterForm = $content->find('form', 0); + if ($newsletterForm) + $newsletterForm->outertext = ''; + + // Remove next and previous article URLs at the bottom + $nextprev = $content->find('div[class="blog-post__next-previous-wrapper"]', 0); + if ($nextprev) + $nextprev->outertext = ''; + + $section = [ $article->find('h3[itemprop="articleSection"]', 0)->plaintext ]; + + $item = array(); + $item['title'] = $header->find('span', 0)->innertext . ': ' + . $header->find('span', 1)->innertext; + + $item['uri'] = $href; + $item['timestamp'] = strtotime($time->datetime); + $item['author'] = $author->innertext; + $item['categories'] = $section; + + $item['content'] = '' . $content->innertext; + + $this->items[] = $item; + + if (count($this->items) >= 10) + break; + } + } +}