|
An Elliott Back production. |
Main /
LocationPHPScriptThe following PHP script will parse the Gold's Gym locations from their website and return them in wiki-like format to easy data collection and mining. Beware, their site for some strange reason requires either cookies or an explicit PHP session ID as a GET parameter. <?php $state_list = array('AL'=>"Alabama", 'AK'=>"Alaska", 'AZ'=>"Arizona", 'AR'=>"Arkansas", 'CA'=>"California", 'CO'=>"Colorado", 'CT'=>"Connecticut", 'DE'=>"Delaware", 'DC'=>"District Of Columbia", 'FL'=>"Florida", 'GA'=>"Georgia", 'HI'=>"Hawaii", 'ID'=>"Idaho", 'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas", 'KY'=>"Kentucky", 'LA'=>"Louisiana", 'ME'=>"Maine", 'MD'=>"Maryland", 'MA'=>"Massachusetts", 'MI'=>"Michigan", 'MN'=>"Minnesota", 'MS'=>"Mississippi", 'MO'=>"Missouri", 'MT'=>"Montana", 'NE'=>"Nebraska", 'NV'=>"Nevada", 'NH'=>"New Hampshire", 'NJ'=>"New Jersey", 'NM'=>"New Mexico", 'NY'=>"New York", 'NC'=>"North Carolina", 'ND'=>"North Dakota", 'OH'=>"Ohio", 'OK'=>"Oklahoma", 'OR'=>"Oregon", 'PA'=>"Pennsylvania", 'RI'=>"Rhode Island", 'SC'=>"South Carolina", 'SD'=>"South Dakota", 'TN'=>"Tennessee", 'TX'=>"Texas", 'UT'=>"Utah", 'VT'=>"Vermont", 'VA'=>"Virginia", 'WA'=>"Washington", 'WV'=>"West Virginia", 'WI'=>"Wisconsin", 'WY'=>"Wyoming"); $url = 'http://goldsgym.com/gym_locator/index.php' . '?PHPSESSID=0ddf43d32b017d3f9b9801d769a30e80&state='; $br = ' [[<<]]'; foreach($state_list as $state=>$name){ $html = file_get_contents($url . $state); echo "|| border=0\n"; echo "||! ''" . $name . "'' ($state) !||\n"; echo "||! Location ||! Address ||! Telephone ||\n"; preg_match_all("~<tr>[\s]*<td> </td>[\s]*<td>(.*?)</td>[\s]*<td>(.*?)" . "<a.*?</a>.*?</td>[\s]*<td>(.*?)</td>[\s]*<td>.*?</td>[\s]*<td>.*?</td>[\s" . "]*<td> </td>[\s]*</tr>~si", $html, $matches); $locations = $matches[1]; $addresses = $matches[2]; $numbers = $matches[3]; for($i = 0; $i < count($locations); $i++){ echo '|| '; echo htmlentities(trim(strip_tags($locations[$i]))); echo ' || '; echo str_replace("\n", ' [[<<]]', htmlentities(trim(strip_tags(str_replace('<br>', "\n", $addresses[$i]))))); echo ' || '; echo htmlentities(trim(strip_tags(str_replace(' ', '', $numbers[$i])))); echo " ||\n"; } echo "\n\n"; } ?>
|