Created
November 14, 2014 19:59
-
-
Save vschmidt94/bf53163182bfcbfab579 to your computer and use it in GitHub Desktop.
Simple PHP web scraper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // bldgcrawler.php | |
| // Loops through sequential get requests to the OSU Campus Map and retrieves | |
| // any additional landmark info as JSON reply. Parse JSON reply and output | |
| // to browser. | |
| // Vaughan Schmidt | |
| // schmicar@onid.engr.oregonstate.edu | |
| // 2014.11.13 | |
| header('Content-Type: application/json'); | |
| $capture = array(); | |
| for($i=447; $i < 1039 ; $i++) { | |
| $url = 'http://oregonstate.edu/campusmap/map/element?location=&locations=' . $i; | |
| $json = file_get_contents($url); | |
| $obj=json_decode($json, true); | |
| $name = $obj["locations"][$i]["name"]; | |
| $abbr = $obj["locations"][$i]["abbrev"]; | |
| $id = $obj["locations"][$i]["id"]; | |
| $lat = $obj["locations"][$i]["marker_location"][1]; | |
| $long = $obj["locations"][$i]["marker_location"][0]; | |
| $addr1 = $obj["locations"][$i]["metadata"]["physical_address"]; | |
| $notes = $obj["locations"][$i]["metadata"]["long_description"]; | |
| if((int)$id > 0) { | |
| echo("(" . (int)$id . ",\"$abbr\",\"$name\",\"$addr1\",NULL,\"Corvallis\",\"OR\",\"97333\"," . (float)$lat . "," . (float)$long . ",\"$notes\",NOW(),NOW()),"); | |
| echo " | |
| "; | |
| } | |
| die(); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment