Last active
June 2, 2016 21:38
-
-
Save jakzal/f7bd31de667e61507925 to your computer and use it in GitHub Desktop.
CSS Selectors with html5
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 | |
<<<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