Skip to content

Instantly share code, notes, and snippets.

@simonw
Created May 20, 2013 17:25
Show Gist options
  • Select an option

  • Save simonw/5613734 to your computer and use it in GitHub Desktop.

Select an option

Save simonw/5613734 to your computer and use it in GitHub Desktop.
var entries = jQuery('div.blogEntry').multiscrape({title: 'h3', abstract: '.abstract', date: '.pubdate'});
jQuery.fn.multiscrape = function(opts) {
var scraped = [];
this.each(function() {
var $this = jQuery(this);
var obj = {};
jQuery.each(opts, function(key, value) {
var val;
if (jQuery.isFunction(value)) {
val = value.apply($this);
} else {
val = $this.find(value).text();
}
if (val) {
val = jQuery.trim(val);
}
obj[key] = val;
});
scraped.push(obj);
});
return scraped;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment