使用phpsimplehtmldomparser解析html标签_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用phpsimplehtmldomparser解析html标签_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4238字,纯文字阅读大概需要7分钟。
内容图文
![使用phpsimplehtmldomparser解析html标签_PHP教程](/upload/InfoBanner/zyjiaocheng/175/a0870d0f30d1411eb2450ec241b71713.jpg)
'; // Extract images foreach($html->find('img') as $element) echo $element->src . '
'; [php] // Create DOM from URL or file $html = file_get_html('http://www.microsoft.com/'); // Extract links foreach($html->find('a') as $element) echo $element->href . '
'; // Extract images foreach($html->find('img') as $element) echo $element->src . '
'; // Create DOM from URL or file $html = file_get_html('http://www.microsoft.com/'); // Extract links foreach($html->find('a') as $element) echo $element->href . '
'; // Extract images foreach($html->find('img') as $element) echo $element->src . '
'; The parser can also be used to modify HTML elements: view plain copy to clipboard print ? Php代码 // Create DOM from string $html = str_get_html('SimpleParser'); $html->find('div', 1)->class = 'bar'; $html->find('div[id=simple]', 0)->innertext = 'Foo'; // Output: FooParser echo $html; [php] // Create DOM from string $html = str_get_html('SimpleParser'); $html->find('div', 1)->class = 'bar'; $html->find('div[id=simple]', 0)->innertext = 'Foo'; // Output: FooParser echo $html; // Create DOM from string $html = str_get_html('SimpleParser'); $html->find('div', 1)->class = 'bar'; $html->find('div[id=simple]', 0)->innertext = 'Foo'; // Output: FooParser echo $html; Do you wish to retrieve content without any tags? view plain copy to clipboard print ? Php代码 echo file_get_html('http://www.yahoo.com/')->plaintext; [php] echo file_get_html('http://www.yahoo.com/')->plaintext; echo file_get_html('http://www.yahoo.com/')->plaintext;In the package files of this parser ([url]http://simplehtmldom.sourceforge.net/[/url]) you can find some scraping examples from digg, imdb, slashdot. Let’s create one that extracts the first 10 results (titles only) for the keyword “php” from Google: view plain copy to clipboard print ? Php代码 $url = 'http://www.google.com/search?hl=en&q=php&btnG=Search'; // Create DOM from URL $html = file_get_html($url); // Match all 'A' tags that have the class attribute equal with 'l' foreach($html->find('a[class=l]') as $key => $info) { echo ($key + 1).'. '.$info->plaintext."
\n"; } [php] $url = 'http://www.google.com/search?hl=en&q=php&btnG=Search'; // Create DOM from URL $html = file_get_html($url); // Match all 'A' tags that have the class attribute equal with 'l' foreach($html->find('a[class=l]') as $key => $info) { echo ($key + 1).'. '.$info->plaintext."
\n"; } $url = 'http://www.google.com/search?hl=en&q=php&btnG=Search'; // Create DOM from URL $html = file_get_html($url); // Match all 'A' tags that have the class attribute equal with 'l' foreach($html->find('a[class=l]') as $key => $info) { echo ($key + 1).'. '.$info->plaintext."
\n"; }NOTE Make sure to include the parser before using any functions of it: view plain copy to clipboard print ? Php代码 include 'simple_html_dom.php'; [php] include 'simple_html_dom.php'; include 'simple_html_dom.php';For more information regarding the usage of this function consider checking the ‘PHP Simple HTML Dom Parser’ Manual. To download the package files use the following URL: [url] 分享到:
http://www.bkjia.com/PHPjc/477857.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477857.htmlTechArticle使用php simple html dom parser解析html标签 用了一下 PHP Simple HTML DOM Parser 解析HTML页面,感觉还不错,它能创建一个DOM tree方便你解析html里面的内...
内容总结
以上是互联网集市为您收集整理的使用phpsimplehtmldomparser解析html标签_PHP教程全部内容,希望文章能够帮你解决使用phpsimplehtmldomparser解析html标签_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。