lang/php
PHP simple-html-dom-parser
C/H
2018. 7. 3. 08:30
- github.com/sunra/php-simple-html-dom-parser
- packagist.org/packages/sunra/php-simple-html-dom-parser
- PHP Simple HTML DOM Parser Manual
Installation
"require": { "sunra/php-simple-html-dom-parser": "1.5.2" }
composer require sunra/php-simple-html-dom-parser
Usage
require_once "vendor/autoload.php"; use Sunra\PhpSimple\HtmlDomParser; ... $dom = HtmlDomParser::str_get_html( $str ); or $dom = HtmlDomParser::file_get_html( $file_name ); $elems = $dom->find($elem_name);
require_once "vendor/autoload.php"; use Sunra\PhpSimple\HtmlDomParser; $url = 'http://naver.com'; $context = stream_context_create([ 'http'=>[ 'header'=>'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36' ]]); $html = HtmlDomParser::str_get_html(file_get_contents($url, false, $context)); //$html = HtmlDomParser::file_get_html($url, FALSE, $context, 0); var_dump( $html );
반응형