Currently trying to scrape some HTML using a DOM scraping library called PHP Simple HTML Dom Parser.
I have the following method:
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;
}
The above method is my attempt at scraping the following 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>
Here is the source document.
The result I get from the above function using var_dump
is:
array(4) {
[0]=>
bool(false)
[1]=>
bool(false)
[2]=>
bool(false)
[3]=>
bool(false)
}
Not quite sure what the issue. If someone could offer me some advice - thank you!