Skip to content

Instantly share code, notes, and snippets.

@moacir
Last active January 1, 2016 15:08
Show Gist options
  • Save moacir/8161756 to your computer and use it in GitHub Desktop.
Save moacir/8161756 to your computer and use it in GitHub Desktop.
Extracting last news from Hacker News using Symfony DomCrawler
<?php
require_once './vendor/autoload.php';
use Symfony\Component\DomCrawler\Crawler;
$content = @file_get_contents('https://news.ycombinator.com/news');
if (!$content) {
die('Not able to get contents from Hacker News :(');
}
$crawler = new Crawler($content);
$filter = $crawler->filter('td.title > a');
foreach ($filter as $element) {
echo $element->textContent . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment