Last active
January 1, 2016 15:08
-
-
Save moacir/8161756 to your computer and use it in GitHub Desktop.
Extracting last news from Hacker News using Symfony DomCrawler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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