mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-03-14 20:21:14 +03:00
[HarvardHealthBlogBridge] New (#4116)
This commit is contained in:
parent
5a68ee0c87
commit
bd90109c70
1 changed files with 56 additions and 0 deletions
56
bridges/HarvardHealthBlogBridge.php
Normal file
56
bridges/HarvardHealthBlogBridge.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
class HarvardHealthBlogBridge extends BridgeAbstract
|
||||
{
|
||||
const NAME = 'Harvard Health Blog';
|
||||
const URI = 'https://www.health.harvard.edu/blog';
|
||||
const DESCRIPTION = 'Retrieve articles from health.harvard.edu';
|
||||
const MAINTAINER = 'tillcash';
|
||||
const MAX_ARTICLES = 10;
|
||||
|
||||
public function collectData()
|
||||
{
|
||||
$dom = getSimpleHTMLDOM(self::URI);
|
||||
$count = 0;
|
||||
|
||||
foreach ($dom->find('div[class="mb-16 md:flex"]') as $element) {
|
||||
if ($count >= self::MAX_ARTICLES) {
|
||||
break;
|
||||
}
|
||||
|
||||
$data = $element->find('a[class="hover:text-red transition-colors duration-200"]', 0);
|
||||
if (!$data) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$url = $data->href;
|
||||
|
||||
$this->items[] = [
|
||||
'content' => $this->constructContent($url),
|
||||
'timestamp' => $element->find('time', 0)->datetime,
|
||||
'title' => $data->plaintext,
|
||||
'uid' => $url,
|
||||
'uri' => $url,
|
||||
];
|
||||
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
private function constructContent($url)
|
||||
{
|
||||
$dom = getSimpleHTMLDOMCached($url);
|
||||
|
||||
$article = $dom->find('div[class*="content-repository-content"]', 0);
|
||||
if (!$article) {
|
||||
return 'Content Not Found';
|
||||
}
|
||||
|
||||
// Remove ads
|
||||
foreach ($article->find('.inline-ad') as $remove) {
|
||||
$remove->outertext = '';
|
||||
}
|
||||
|
||||
return $article->innertext;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue