Skip to content

Commit

Permalink
[EconomistBridge] Add cookie (#4173)
Browse files Browse the repository at this point in the history
* [EconomistBridge] Add cookie

* [EconomistBridge] Fix lint
  • Loading branch information
SqrtMinusOne authored Jul 30, 2024
1 parent cb91afb commit aa39898
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
29 changes: 28 additions & 1 deletion bridges/EconomistBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ class EconomistBridge extends FeedExpander
const CACHE_TIMEOUT = 3600; //1hour
const DESCRIPTION = 'Returns the latest articles for the selected category';

const CONFIGURATION = [
'cookie' => [
'required' => false,
]
];

const PARAMETERS = [
'global' => [
'limit' => [
Expand Down Expand Up @@ -99,8 +105,20 @@ public function collectData()

protected function parseItem(array $item)
{
$headers = [];
if ($this->getOption('cookie')) {
$headers = [
'Authority: www.economist.com',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-language: en-US,en;q=0.9',
'Cache-control: max-age=0',
'Cookie: ' . $this->getOption('cookie'),
'Upgrade-insecure-requests: 1',
'User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
];
}
try {
$dom = getSimpleHTMLDOM($item['uri']);
$dom = getSimpleHTMLDOM($item['uri'], $headers);
} catch (Exception $e) {
$item['content'] = $e->getMessage();
return $item;
Expand Down Expand Up @@ -209,6 +227,15 @@ private function processContent($html, $elem)
foreach ($elem->find('a.ds-link-with-arrow-icon') as $a) {
$a->parent->removeChild($a);
}
// Sections like "Leaders on day X"
foreach ($elem->find('div[data-tracking-id=content-well-chapter-list]') as $div) {
$div->parent->removeChild($div);
}
// "Explore more" section
foreach ($elem->find('h3[id=article-tags]') as $h3) {
$div = $h3->parent;
$div->parent->removeChild($div);
}

// The Economist puts infographics into iframes, which doesn't
// work in any of my readers. So this replaces iframes with
Expand Down
5 changes: 4 additions & 1 deletion docs/10_Bridge_Specific/Economist.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# EconomistWorldInBriefBridge
# EconomistWorldInBriefBridge and EconomistBridge

In May 2024, The Economist finally fixed its paywall, and it started requiring authorization. Which means you can't use this bridge unless you have an active subscription.

Expand All @@ -15,4 +15,7 @@ Once you've done this, add the cookie to your `config.ini.php`:
```
[EconomistWorldInBriefBridge]
cookie = "<value>"
[EconomistBridge]
cookie = "<value>"
```

0 comments on commit aa39898

Please sign in to comment.