PHP code example of kurozumi / web-scraper-bundle
1. Go to this page and download the library: Download kurozumi/web-scraper-bundle library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kurozumi / web-scraper-bundle example snippets
namespace App\Command;
use Kurozumi\WebScraperBundle\Service\Context;
use Kurozumi\WebScraperBundle\Service\Scraper\RssScraper;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
#[AsCommand(
name: 'app:scraper'
)]
class ScraperCommand extends Command
{
private Context $context;
public function __construct(Context $context)
{
$this->context = $context;
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$feeds = [
'https://aaa.rss.xml',
'https://bbb.rss.xml'
];
$items = [];
foreach ($feeds as $feed) {
$data = $this->content->getData($feed);
if (null !== $data) {
foreach ($data['items'] as $item) {
switch ($data['name']) {
case RssScraper::class:
$items[] = [
'title' => $item->filter('title')->text(),
'url' => $item->filter('link')->text()
];
break;
}
}
}
}
print_r($items);
return Command::SUCCESS;
}
}