Skip to content

Instantly share code, notes, and snippets.

@jakzal
Last active June 2, 2016 21:38
Show Gist options
  • Save jakzal/f7bd31de667e61507925 to your computer and use it in GitHub Desktop.
Save jakzal/f7bd31de667e61507925 to your computer and use it in GitHub Desktop.
CSS Selectors with html5
<?php
<<<CONFIG
packages:
- "masterminds/html5: 2.*@dev"
- "symfony/css-selector: ~2.3"
CONFIG;
/**
* Run this script with melody (http://melody.sensiolabs.org/):
*
* melody run https://gist.github.com/jakzal/f7bd31de667e61507925
*/
use Masterminds\HTML5;
use Symfony\Component\CssSelector\CssSelector;
$html = new HTML5();
$dom = $html->loadHTML(file_get_contents('http://www.cascade-framework.com/'));
$expression = CssSelector::toXPath('.highlights .cell');
$xpath = new DOMXpath($dom);
$elements = $xpath->query($expression);
// echo $html->saveHTML($dom);
echo $html->saveHTML($elements);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment