Skip to content

Instantly share code, notes, and snippets.

@giorrrgio
Last active August 29, 2015 14:06
Show Gist options
  • Save giorrrgio/37d9c9b4d7f2ef7889c3 to your computer and use it in GitHub Desktop.
Save giorrrgio/37d9c9b4d7f2ef7889c3 to your computer and use it in GitHub Desktop.
HtmlScraper
{
"require": {
"symfony/dom-crawler": "*",
"symfony/css-selector": "*"
}
}
<?php
require_once 'vendor/autoload.php';
<?php
use Symfony\Component\DomCrawler\Crawler;
require_once 'vendor/autoload.php';
$html = '<html><body><p>Hello World!</p></body></html>';
$crawler = new Crawler($html);
var_dump($crawler->html());
<?php
use Symfony\Component\DomCrawler\Crawler;
require_once 'vendor/autoload.php';
$url = 'http://en.wikipedia.org/wiki/Flying_Spaghetti_Monster';
$html = file_get_contents($url);
$crawler = new Crawler($html);
$history = $crawler
->filter('h2:contains("History") + p');
var_dump($history->html());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment