做个记录

symfony/dom-crawler 使用入门

> composer require "symfony/dom-crawler"
<?php
use Symfony\Component\DomCrawler\Crawler;
require 'vendor/autoload.php';

$html = <<<'HTML'
<!DOCTYPE html>
<html>
    <body>
        <p class="message">Hello World!</p>
        <p>Hello Crawler!</p>
    </body>
</html>
HTML;

$crawler = new Crawler($html);

foreach ($crawler as $domElement) {
    var_dump($domElement->nodeName);
}

http://symfony.com/doc/current/components/dom_crawler.html

https://segmentfault.com/q/1010000009019518

发表评论

Close Menu