Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EconomistBridge] Fixes for fetching new page structure #1836

Merged
merged 8 commits into from
Nov 29, 2020
35 changes: 21 additions & 14 deletions bridges/EconomistBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,28 @@ public function collectData() {
$html = getSimpleHTMLDOM(self::URI . '/latest/')
or returnServerError('Could not fetch latest updates form The Economist.');

foreach($html->find('article') as $element) {
foreach($html->find('div.teaser') as $element) {

$a = $element->find('a.headline-link', 0);
$href = $a->href;

if (substr($href, 0, 4) != 'http')
$href = self::URI . $a->href;

$a = $element->find('a', 0);
$href = self::URI . $a->href;
$full = getSimpleHTMLDOMCached($href);
$article = $full->find('article', 0);
$header = $article->find('span[itemprop="headline"]', 0);
$headerimg = $article->find('div[itemprop="image"]', 0)->find('img', 0);
$author = $article->find('p[itemprop="byline"]', 0);
$time = $article->find('time', 0);
$content = $article->find('div[itemprop="text"]', 0);
$section = array( $article->find('strong[itemprop="articleSection"]', 0)->plaintext );

$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);
// Author
if ($author)
$author = substr($author->innertext, 3, strlen($author));
else
$author = 'The Economist';

// Remove newsletter subscription box
$newsletter = $content->find('div[class="newsletter-form__message"]', 0);
Expand All @@ -40,19 +51,15 @@ public function collectData() {
if ($nextprev)
$nextprev->outertext = '';

$section = array( $article->find('h3[itemprop="articleSection"]', 0)->plaintext );

$item = array();
$item['title'] = $header->find('span', 0)->innertext . ': '
. $header->find('span', 1)->innertext;

$item['title'] = $header->innertext;
$item['uri'] = $href;
$item['timestamp'] = strtotime($time->datetime);
$item['author'] = $author->innertext;
$item['author'] = $author;
$item['categories'] = $section;

$item['content'] = '<img style="max-width: 100%" src="'
. $a->find('img', 0)->src . '">' . $content->innertext;
. $headerimg->src . '">' . $content->innertext;

$this->items[] = $item;

Expand Down