Skip to content

Instantly share code, notes, and snippets.

@mingan
Created September 20, 2014 17:04
Show Gist options
  • Save mingan/4408d004fd1f322479b0 to your computer and use it in GitHub Desktop.
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
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