Created
September 20, 2014 17:04
-
-
Save mingan/4408d004fd1f322479b0 to your computer and use it in GitHub Desktop.
Simple jQuery code to extract basic information from ArchDaily (http://www.archdaily.com/tag/vienna) to CSV
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
data = [] | |
$('#st1>div').each(function (i, div) { | |
project = {}; | |
$link = $(div).find('h3 a'); | |
project['url'] = $link.attr('href'); | |
project['name'] = $link.text(); | |
$specs = $(div).find('.specs') | |
if ($specs.length) { | |
specs = $specs.text(); | |
arch = specs.match(/Architects: (.+)/); | |
if (arch) { | |
project['architect'] = arch[1]; | |
} | |
year = specs.match(/Year: (.+)/); | |
if (year) { | |
project['year'] = year[1]; | |
} | |
project['image'] = $(div).find('figure img').attr('src'); | |
} | |
data.push(project); | |
}); | |
csv = ['Project,URL,Image,Architect,Year']; | |
$.each(data, function(i, project) { | |
str = [ | |
project['name'], | |
project['url'], | |
project['image'], | |
project['architect'], | |
project['year'], | |
]; | |
csv.push(str.join(', ')); | |
}); | |
csv.join("\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment