forked from sedenardi/snapchat-map
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseWiki.html
More file actions
50 lines (47 loc) · 2.02 KB
/
parseWiki.html
File metadata and controls
50 lines (47 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<html>
<head>
<title>Wikipedia Parser</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
</head>
<body style="padding:20px;">
<h3>Parse US City Population Density from - <a href="view-source:http://en.wikipedia.org/wiki/List_of_United_States_cities_by_population" target="_blank">http://en.wikipedia.org/wiki/List_of_United_States_cities_by_population</a></h3>
<br />
<div>
<textarea class="form-control" id="inputArea" placeholder="Paste source from http://en.wikipedia.org/wiki/List_of_United_States_cities_by_population" rows="10"></textarea>
<button type="button" class="btn btn-success" id="btnParse">Get Area Codes</button>
</div>
<br/>
<div>
<h5>JSON<span id="lenJSON"></span></h5>
<textarea class="form-control" id="outputJSONArea" rows="10"></textarea>
</div>
</body>
</html>
</script>
<script type="text/javascript">
$('#btnParse').click(function() {
var rawHtml = $('#inputArea').val();
var rows = $(rawHtml).find('.wikitable:first').find('tr');
var array = [];
$.each(rows, function(i,v) {
if (i > 0) { //ignore header
var rank = $(v).find('td:first').html();
var city = $(v).find('td').eq(1).find('a:first').html();
var state = $(v).find('td').eq(2).find('a:first').html();
$(v).find('td').eq(3).find('span:first').remove();
var pop2012 = $(v).find('td').eq(3).html().replace(/,/g , '');
var latlon = $(v).find('td').eq(9).html().split(' ');
var lat = latlon[0].substring(0,(latlon[0].length-2));
var lon = '-' + latlon[1].substring(0,(latlon[0].length-2));
array.push({
lat: lat,
lng: lon,
count: pop2012
});
}
});
$('#outputJSONArea').val(JSON.stringify(array));
});
</script>