Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用简单html dom解析器PHP解析html时出现致命错误_Php_Parsing_Dom_Attributes - Fatal编程技术网

尝试使用简单html dom解析器PHP解析html时出现致命错误

尝试使用简单html dom解析器PHP解析html时出现致命错误,php,parsing,dom,attributes,Php,Parsing,Dom,Attributes,我试图从网站上获得评论和其他信息。我可以从第一页获取所有评论,但我想解析所有评论页面,并获取每一条评论、作者和发布时间。对于第一页代码,它还可以为下一页找到正确的url,但当它尝试解析下一页时,我会遇到以下错误:致命错误:在C:…/simple\u html\u dom.php第1113行对非对象调用成员函数find() 如何修复此问题并解析所有页面 $url = "http://apollo.tvnet.lv/komentari/zinas/687521/1"; $nextLink = $u

我试图从网站上获得评论和其他信息。我可以从第一页获取所有评论,但我想解析所有评论页面,并获取每一条评论、作者和发布时间。对于第一页代码,它还可以为下一页找到正确的url,但当它尝试解析下一页时,我会遇到以下错误:致命错误:在C:…/simple\u html\u dom.php第1113行对非对象调用成员函数find()

如何修复此问题并解析所有页面

$url = "http://apollo.tvnet.lv/komentari/zinas/687521/1";

$nextLink = $url;    

while ($nextLink) {
   echo "<hr>nextLink: $nextLink<br>";
   //Create a DOM object
   $html = new simple_html_dom();
   // Load HTML from a url
   $html->load_file($nextLink);

$articles = $html->find('div [class=article-comment]');

foreach($articles as $article) {

    $content = $article->find('div[class=article-comment-content]',0)->innertext;

    $author = $article->find('strong[class=article-comment-author]',0)->innertext;

    $date = $article->find('time[class=article-comment-date]',0)->innertext;


    printf("AUTHOR: %s </br> CONTENT: %s </br> Time: %s </br>", $author, $content, $date);

  $nextLink = ( ($temp = $html->find(' a[class=pageing-button-next]', 0)) ? "http://apollo.tvnet.lv".$temp->href : NULL );

// Clear DOM object
$html->clear();
unset($html);
$url=”http://apollo.tvnet.lv/komentari/zinas/687521/1";
$nextLink=$url;
while($nextLink){
echo“
nextLink:$nextLink
”; //创建DOM对象 $html=新的简单html\U dom(); //从url加载HTML $html->load_文件($nextLink); $articles=$html->find('div[class=article comment]”); foreach($articles作为$article){ $content=$article->find('div[class=article comment content],0)->innertext; $author=$article->find('strong[class=article comment author],0)->innertext; $date=$article->find('time[class=article comment date]',0)->innertext; printf(“作者:%s
内容:%s
时间:%s
”,$AUTHOR,$CONTENT,$date); $nextLink=($temp=$html->find('a[class=paging button next]',0))?”http://apollo.tvnet.lv“$temp->href:NULL); //清除DOM对象 $html->clear(); 未结算($html);

}

看起来您要加载的文件不可访问,或者是无效的html。它是有效的html,并且文件确实可访问调用
load\u file
后是否尝试使用var\u dump
?var\u dump没有帮助:($html=file\u get\u html($nextLink);这解决了我的问题