【发布时间】:2017-04-09 10:08:44
【问题描述】:
我正在尝试使用 PHP dom 解析器从论坛站点解析与帖子相关的语句。它在我们插入页面的单个 url 时有效,但是当我们尝试应用 while 循环逻辑时,它有点只打印一个页面多次..
我的代码如下::
<?php
set_time_limit(3600);
$i = 1;
$e = 839304-$i;
while(true){
require_once('dom/simple_html_dom.php');
$html =file_get_html('http://www.usmleforum.com/files/forum/2017/1/'.$e.'.php');
foreach ($html->find("tr") as $row) {
$element = $row->find('td.Text2',0);
if ($element == null) { continue; }
$textNode = array_filter($element->nodes, function ($n) {
return $n->nodetype == 3; //Text node type, like in jQuery
});
if (!empty($textNode)) {
$text = current($textNode);
echo $text."<br>";
}
}
$i++;
}
?>
正如结果所示,它只打印第 839303 页的语句,但它打印了多次并且仍然加载......所以很明显这段代码以某种方式跳过了 $i++ 行并再次运行......
感谢任何帮助...
【问题讨论】:
标签: php mysql web-crawler