mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-22 17:45:40 +03:00
8e8028b786
* first working version --------- Co-authored-by: Dag <me@dvikan.no>
73 lines
No EOL
2.8 KiB
PHP
73 lines
No EOL
2.8 KiB
PHP
<?php
|
|
|
|
use Facebook\WebDriver\WebDriverBy;
|
|
use Facebook\WebDriver\WebDriverExpectedCondition;
|
|
|
|
class ScalableCapitalBlogBridge extends WebDriverAbstract
|
|
{
|
|
const NAME = 'Scalable Capital Blog';
|
|
const URI = 'https://de.scalable.capital/blog';
|
|
const DESCRIPTION = 'Alle Artikel';
|
|
const MAINTAINER = 'hleskien';
|
|
|
|
/**
|
|
* Adds accept language german to the Chrome Options.
|
|
*
|
|
* @return Facebook\WebDriver\Chrome\ChromeOptions
|
|
*/
|
|
protected function getBrowserOptions()
|
|
{
|
|
$chromeOptions = parent::getBrowserOptions();
|
|
$chromeOptions->addArguments(['--accept-lang=de']);
|
|
return $chromeOptions;
|
|
}
|
|
|
|
/**
|
|
* Puts the content of the first page into the $items array.
|
|
*
|
|
* @throws Facebook\WebDriver\Exception\NoSuchElementException
|
|
* @throws Facebook\WebDriver\Exception\TimeoutException
|
|
*/
|
|
public function collectData()
|
|
{
|
|
parent::collectData();
|
|
|
|
try {
|
|
// wait until last item is loaded
|
|
$this->getDriver()->wait()->until(WebDriverExpectedCondition::visibilityOfElementLocated(
|
|
WebDriverBy::xpath('//div[contains(@class, "articles")]//div[@class="items"]//div[contains(@class, "item")][15]')
|
|
));
|
|
$this->setIcon($this->getDriver()->findElement(WebDriverBy::xpath('//link[@rel="shortcut icon"]'))->getAttribute('href'));
|
|
|
|
$items = $this->getDriver()->findElements(WebDriverBy::xpath('//div[contains(@class, "articles")]//div[@class="items"]//div[contains(@class, "item")]'));
|
|
foreach ($items as $item) {
|
|
$feedItem = new FeedItem();
|
|
|
|
$feedItem->setEnclosures(['https://de.scalable.capital' . $item->findElement(WebDriverBy::tagName('img'))->getAttribute('src')]);
|
|
$heading = $item->findElement(WebDriverBy::tagName('a'));
|
|
$feedItem->setTitle($heading->getText());
|
|
$feedItem->setURI('https://de.scalable.capital' . $heading->getAttribute('href'));
|
|
$feedItem->setContent($item->findElement(WebDriverBy::xpath('.//div[@class="summary"]'))->getText());
|
|
$date = $item->findElement(WebDriverBy::xpath('.//div[@class="published-date"]'))->getText();
|
|
$feedItem->setTimestamp($this->formatItemTimestamp($date));
|
|
$feedItem->setAuthor($item->findElement(WebDriverBy::xpath('.//div[@class="author"]'))->getText());
|
|
|
|
$this->items[] = $feedItem;
|
|
}
|
|
} finally {
|
|
$this->cleanUp();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Converts the given date (dd.mm.yyyy) into a timestamp.
|
|
*
|
|
* @param $value string
|
|
* @return int
|
|
*/
|
|
protected function formatItemTimestamp($value)
|
|
{
|
|
$formatter = new IntlDateFormatter('de', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
|
|
return $formatter->parse($value);
|
|
}
|
|
} |