mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-07-24 20:55:11 +02:00
Adopt WebDriverAbstract as a solution for active (JavaScript) websites (#3971)
* first working version --------- Co-authored-by: Dag <me@dvikan.no>
This commit is contained in:
parent
ff7840d60f
commit
8e8028b786
7 changed files with 473 additions and 1 deletions
73
bridges/ScalableCapitalBlogBridge.php
Normal file
73
bridges/ScalableCapitalBlogBridge.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue