怎么在php中使用simple_html_dom解析HTML

发布时间:2021-03-31 15:56:21 作者:Leah
来源:亿速云 阅读:283

今天就跟大家聊聊有关怎么在php中使用simple_html_dom解析HTML,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

用法示例:

<?php
// example of how to use basic selector to retrieve HTML contents
include('../simple_html_dom.php');
// get DOM from URL or file
$html = file_get_html('http://www.google.com/');
// find all link
foreach($html->find('a') as $e) 
  echo $e->href . '<br>';
// find all image
foreach($html->find('img') as $e)
  echo $e->src . '<br>';
// find all image with full tag
foreach($html->find('img') as $e)
  echo $e->outertext . '<br>';
// find all div tags with id=gbar
foreach($html->find('div#gbar') as $e)
  echo $e->innertext . '<br>';
// find all span tags with class=gb1
foreach($html->find('span.gb1') as $e)
  echo $e->outertext . '<br>';
// find all td tags with attribite align=center
foreach($html->find('td[align=center]') as $e)
  echo $e->innertext . '<br>';
// extract text from table
echo $html->find('td[align="center"]', 1)->plaintext.'<br><hr>';
// extract text from HTML
echo $html->plaintext;
?>

看完上述内容,你们对怎么在php中使用simple_html_dom解析HTML有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

推荐阅读:
  1. PHP - 如何解析HTML文件
  2. 怎么在Python项目中使用lxml库解析html文件

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php html

上一篇:使用DbManager怎么判断后台权限

下一篇:如何正确的使用Puppet

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》