PHP简单DOM解析器以刮取方法返回布尔值/空值

青菜

当前正在尝试使用称为PHP Simple HTML Dom Parser的DOM抓取库来抓取一些HTML。

我有以下方法:

public function getFourLevels() {
    // Iterate through the four pollen levels [Wunderground only has four day
    // pollen prediction]
    for($i = 0; $i < 4; $i++) {

        // Get the raw level
        $rawLevels = $this->html
            ->find("td.text-center.even-four", $i)
            ->plaintext;

        // Clean the raw level
        $level = substr(
            $rawLevels,
            PollenBuddy::LEVELS
        );

        // Push each date to the dates array
        array_push($this->levels, $level);
    }

    return $this->levels;
}

上面的方法是我尝试抓取以下HTML的尝试:

    <td class="text-center even-four">
    <strong>Sunday</strong>
    <div>February 15, 2015</div>
    </td>
    <td class="text-center even-four">
    <strong>Monday</strong>
    <div>February 16, 2015</div>
    </td>
    <td class="text-center even-four">
    <strong>Tuesday</strong>
    <div>February 17, 2015</div>
    </td>
    <td class="text-center even-four">
    <strong>Wednesday</strong>
    <div>February 18, 2015</div>
    </td>

这是源文档

我从上面的函数中使用的结果var_dump是:

array(4) {
  [0]=>
  bool(false)
  [1]=>
  bool(false)
  [2]=>
  bool(false)
  [3]=>
  bool(false)
}

不太清楚是什么问题。如果有人可以给我一些建议-谢谢!

青菜

使用:

        // Get the raw level
        $rawLevel = $this->html
            ->find("td.even-four", $i)
            ->plaintext;

返回正确的数据。

从此链接中找到:简单的html dom-类名中的空格

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章