PHP Simple DOM Parser在Scratching方法中返回布尔值/Null


PHP Simple DOM Parser Returning Booleans/Null in Scraping Method

当前正在尝试使用名为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-space