【发布时间】:2011-02-26 03:50:41
【问题描述】:
我正在尝试查找 div 中的所有链接,然后打印这些链接。
我正在使用 Simple HTML Dom 来解析 HTML 文件。这是我到目前为止的内容,请阅读内联 cmets 并让我知道我哪里出错了。
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>
感谢大家的帮助
【问题讨论】: