从网页上抓取内容的库simple_html_dom
来源:互联网 发布:qq三国乱世挂机软件 编辑:程序博客网 时间:2024/05/18 02:49
<?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
- Python抓取one网页上的内容
- php抓取网页上的指定内容
- php用simple_html_dom抓取网页 Segmentation fault
- 黑马程序员-从网页抓取内容的要点
- 网页内容抓取 图片的抓取方法
- 抓取网页内容的函数
- [python]抓取网页的内容
- 有关网页抓取的内容
- php抓取页面simple_html_dom的使用教程
- 抓取网页萃取网页内容的代码
- htmlparser实现从网页上抓取数据
- 实现从网页上抓取数据(htmlparser)
- php网页解析器的应用 simple_html_dom
- 用Python的Lxml库抓取网页内容
- simple_html_dom抓取程序
- delphi 抓取网页内容的程序
- 用于抓取网页内容的常用正则
- android10_开发环境
- 二叉树的宽度
- 电子产品新技术
- 哈尔小波变换
- Python dictionary 字典
- 从网页上抓取内容的库simple_html_dom
- 执行程序的内存分布总结
- android ddms 备忘
- 《游戏编程入门》学习笔记2——启程
- 压缩排除某个目录
- 还原一个真实的互联网隐私观
- 英语四六级
- 1002 A + B Problem II
- windows中结束线程的方式