dongqiao8502 2017-02-02 21:23
浏览 41

表格使用HTML DOM Parser进行报废

I would like to scrape the table t-02 from https://wyniki.tge.pl/wyniki/rdn/ with HTML DOM Parser. I created simple code but I was getting errors:

Fatal error: Call to a member function find() on null in /Users/piotrek/Sites/foo/index.html on line 3

My first code:

<?php
    include ("simple_html_dom.php");
    $html=file_get_html("https://wyniki.tge.pl/pl/wyniki/rdn/");
    $tables=$html->find("table[@class=t-02]");
    foreach($tables->find("tr") as $a) {
        foreach($a->find("td") as $element) {
            echo $element;
        }
    }
?>

I changed the code to print innertext and it worked:

<?php
    include_once ("simple_html_dom.php");
    $html=file_get_html("https://wyniki.tge.pl/pl/wyniki/rdn/");
    $title=$html->find("table[@class=t-02]",0)->innertext;
    echo $title
?>

I changed only code so what was wrong with first approach? What was the reason of fatal error?

  • 写回答

1条回答 默认 最新

  • duanduo3712 2017-02-02 21:30
    关注

    The error is saying that the $html object is null, so there is nothing to perform the find method against. Do you have the simple_html_dom.php file in the same directory?

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效