Skip to content

Instantly share code, notes, and snippets.

@iggyvolz
Last active March 3, 2020 06:38
Show Gist options
  • Save iggyvolz/7be402966ce757b8e4a4596e865eb54f to your computer and use it in GitHub Desktop.
Save iggyvolz/7be402966ce757b8e4a4596e865eb54f to your computer and use it in GitHub Desktop.
<?php
$conts = file_get_contents("https://projects.fivethirtyeight.com/2020-primary-forecast/");
$obj = [];
foreach(explode("\n", $conts) as $line) {
$line = trim($line);
if(preg_match("/^interactivePage\\.([a-z]+) = (.+);$/", $line, $matches)) {
[$_, $key, $value] = $matches;
if($value[0] === "'") $value = str_replace("'", '"', $value);
$obj[$key] = json_decode($value, true);
}
}
var_dump($obj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment