Changeset - e31a9001e849
[Not reviewed]
default
0 1 0
Ethan Zonca - 15 years ago 2010-10-16 01:12:57
ez@ethanzonca.com
Get the correct table. Test to see if this works with the nested table setup
1 file changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
school.d/umich.inc
Show inline comments
 
@@ -26,23 +26,23 @@ function umich_instructions_html()
 
  <li>Wait until it's your turn to register and grab your preferred sections before they fill up!</li>
 
</ol>
 
EOF;
 
}
 

	
 
/** Parse html at URL into array, first row is row headers */
 
function table_parse($url) {
 
function umich_table_parse($url) {
 
  $arr = array();
 
  $dom = new DOMDocument;
 
  $html = file_get_contents($url);
 
  if(!$html){
 
    return 1;
 
  }
 
  $dom->loadHTML($html);
 
  $dom->preserveWhiteSpace = false;
 
  $tables = $dom->getElementsByTagName('table');
 
  $rows = $tables->item(0)->getElementsByTagName('tr'); // Get first table on page 
 
  $rows = $tables->item(2)->getElementsByTagName('tr'); // Get first table on page 
 
  foreach ($rows as $rownum => $row) {
 
    $cols = $row->getElementsByTagName('td');
 
    foreach($cols as $colnum => $col){
 
      $arr[$rownum][$colnum] = $col->nodeValue;
 
    }
 
  }
 
@@ -56,11 +56,11 @@ function umich_crawl($season, $year) {
 
  $basepath = "http://www.lsa.umich.edu/cg/cg_results.aspx";
 
  $yearsyn = 1810 + $year; // Weird year synonym name where 2000 == 1800
 
  $basepath .= "?termArray={$season}_{$year}_${yearsyn}&cgtype=ug"
 
  $season = strtolower($season);
 
  $tables = array();
 
  foreach($departments as $department) {
 
    $tables[$department] = table_parse($basepath . '&department=' . $department . '&allsections=true&show=1000');
 
    $tables[$department] = umich_table_parse($basepath . '&department=' . $department . '&allsections=true&show=1000');
 
  }
 
  return $tables;
 
}
 

	
0 comments (0 inline, 0 general)