simple_html_dom使用小结
来源:互联网 发布:数据修真 编辑:程序博客网 时间:2024/06/08 09:28
<?phpinclude "simple_html_dom.php" ;// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');
// Find all images
foreach($html->find('img') as $element)
echo $element->src . '<br>';
// Find all links
foreach($html->find('a') as $element)
echo $element->href . '<br>';
// Create DOM from URL
$html = file_get_html('http://slashdot.org/');
// Find all article blocks
foreach($html->find('div.article') as $article) {
$item['title'] = $article->find('div.title', 0)->plaintext;
$item['intro'] = $article->find('div.intro', 0)->plaintext;
$item['details'] = $article->find('div.details', 0)->plaintext;
$articles[] = $item;
}
print_r($articles);
// Create DOM from string
$html = str_get_html('<div id="hello">Hello</div><div id="world">World</div>'); $html->find('div', 1)->class = 'bar';
$html->find('div[id=hello]', 0)->innertext = 'foo';
echo $html; // Output: <div id="hello">foo</div><div id="world" class="bar">World</div>
$ret = $html->find('a');
// Find (N)th anchor, returns element object or null if not found (zero based)
$ret = $html->find('a', 0);
// Find lastest anchor, returns element object or null if not found (zero based)
$ret = $html->find('a', -1);
// Find all <div> with the id attribute
$ret = $html->find('div[id]');
// Find all <div> which attribute id=foo
$ret = $html->find('div[id=foo]');
$ret = $html->find('#foo');
// Find all element which class=foo
$ret = $html->find('.foo');
// Find all element has attribute id
$ret = $html->find('*[id]');
// Find all anchors and images
$ret = $html->find('a, img');
// Find all anchors and images with the "title" attribute
$ret = $html->find('a[title], img[title]');
$es = $html->find('ul li');
// Find Nested <div> tags
$es = $html->find('div div div');
// Find all <td> in <table> which class=hello
$es = $html->find('table.hello td');
// Find all td tags with attribite align=center in table tags
$es = $html->find(''table td[align=center]');
$html = str_get_html("<div>foo <b>bar</b></div>");
$e = $html->find("div", 0);
echo $e->tag; // Returns: " div"
echo $e->outertext; // Returns: " <div>foo <b>bar</b></div>"
echo $e->innertext; // Returns: " foo <b>bar</b>"
echo $e->plaintext; // Returns: " foo bar"
6.DOM traversing 方法
echo $html->find("#div1", 0)->children(1)->children(1)->children(2)->id;
// or
echo $html->getElementById("div1")->childNodes(1)->childNodes(1)->childNodes(2)->getAttribute('id');
function my_callback($element) {
// Hide all <b> tags
if ($element->tag=='b')
$element->outertext = '';
}
// Register the callback function with it's function name
$html->set_callback('my_callback');
// Callback function will be invoked while dumping
echo $html;
- simple_html_dom使用小结
- simple_html_dom使用小结
- simple_html_dom使用小结
- simple_html_dom使用小结
- simple_html_dom使用小结
- simple_html_dom.php 使用 乱码处理<作者:gaoming13>
- simple_html_dom使用不当导致的内存泄漏
- php抓取页面simple_html_dom的使用教程
- 抓取微博热词,使用simple_html_dom来操作html数据
- simple_html_dom抓取程序
- php simple_html_dom html 解析
- php simple_html_dom网页采集
- simple_html_dom(入门实例)
- php解析html类库simple_html_dom
- php解析html类库simple_html_dom
- curl配合simple_html_dom的方法
- [小结]svn基本使用小结
- php网页解析器的应用 simple_html_dom
- Unity3D Shader官方教程翻译(四)----Shader语法:SubShader
- 数理逻辑:公理化算术(9)递归函数
- 幻灯片效果
- CPU Performance Statistics
- MonkeyRunner_学习地址
- simple_html_dom使用小结
- windows核心编程--作业相关
- spring集成jotm实现JTA分布式事务管理
- Linux驱动学习记录 devfs_mk_cdev
- 数独:9行9列表格,各行各列都填上1-9,且各行各列不能有重复数字
- .net后台生成meta 并控制meta在head里顺序
- Unity3D Shader官方教程翻译(五)----Shader语法:Pass
- 关于变量的各种运算自增(自减)总结:
- primary key与unique的区别