for ($i = 0; $i <= $days_forward; $i++) { // Get the page for the day $data_string = date('d-m-Y', $current_time + $day_interval * $i); $url = "http://www.seattlechannel.org/schedule/default.asp?whichDay=" . $data_string; $html = scraperwiki::scrape($url); $dom = new simple_html_dom(); $dom->load($html); // This is the most accurate way to get the fields, but we only // want to do two at a time. $set = 0; foreach ($dom->find('td.channelText') as $data) { if ($set % 2 == 0) { $time = custom_clean($data->plaintext); $record = array(); } else { $link = $data->find('a'); $record = array('id' => $id, 'timestamp' => $current_time, 'program_date' => $data_string, 'program' => custom_clean($link[0]->plaintext), 'time' => $time, 'link' => $program_link_base . $link[0]->href); scraperwiki::save(array('id'), $record); $time = ''; $id += 1; } $set += 1; } } /** * Function to clean up strings */ function custom_clean($value) { return trim(str_replace(' ', ' ', $value)); }
// Define types array $types = array('images/leafrecyclegarbagecal.gif' => 'Leaf, Recycling, Garbage', 'images/leafgarbagecal.gif' => 'Leaf, Garbage', 'images/garbagecal.gif' => 'Garbage', 'images/leafrecyclecal.gif' => 'Leaf, Recycling'); $id = 0; for ($i = $start_id; $i <= $end_id; $i++) { // Get the page for the day $query_string = '?PC=' . $i . '&Month=' . $month . '&FC=A&D=6'; $url = $base_link . $query_string; $html = scraperwiki::scrape($url); $record = array(); if (trim($html) != $empty_page) { $record['id'] = $id; $dom = new simple_html_dom(); $dom->load($html); // Get address $address_dom = $dom->find('table#Table2 tr td[width="540"] font'); $record['address'] = custom_clean(str_replace('Service Address:', '', $address_dom[0]->plaintext)); // Find date $days_dom = $dom->find('table#Table3 tr td[width="14.28%"] font'); foreach ($days_dom as $day_dom) { // Check for image $image_dom = $day_dom->find('img'); if (!empty($image_dom[0])) { $record['date'] = $year . '-' . $month . '-' . $day_dom->plaintext; $record['type'] = $types[$image_dom[0]->src]; scraperwiki::save(array('id'), $record); $id += 1; } } } } /**