我正在尝试查找div中的所有链接,然后打印这些链接。查找并打印DIV中的所有链接
我正在使用Simple HTML Dom来解析HTML文件。以下是我迄今为止的内容,请阅读内嵌评论,并让我知道我的错在哪里。
include('simple_html_dom.php');
$html = file_get_html('tester.html');
$articles = array();
//find the div the div with the id abcde
foreach($html->find('#abcde') as $article) {
//find all a tags that have a href in the div abcde
foreach($article->find('a[href]') as $link){
//if the href contains singer then echo this link
if(strstr($link, 'singer')){
echo $link;
}
}
}
目前发生的是,上述需要很长的时间来加载(从来没有得到它结束)。我打印了每个循环中所做的事情,因为等待时间太长,我发现它经历的事情我不需要它!这表明我的代码是错误的。
的HTML基本上是这样的:
<div id="abcde">
<!-- lots of html elements -->
<!-- lots of a tags -->
<a href="singer/tom" />
<img src="image..jpg" />
</a>
</div>
感谢所有使用该API的任何帮助
真棒,它的工作马上!我必须为选择器使用JQuery模式。 – Abs 2010-06-01 00:34:43