Skip to content

Instantly share code, notes, and snippets.

@qcom
Created June 29, 2012 18:09
Show Gist options
  • Save qcom/3019709 to your computer and use it in GitHub Desktop.
Save qcom/3019709 to your computer and use it in GitHub Desktop.
casperjs scraper
var skus = [113247,113248,113249];
var sku = [113247];
casper.start('http://bradyid.com', function() {
this.fill('form[action="/bradyid/catalog/siteSearchResultsView.do"]', { 'searchTerms': sku}, true);
});
var url = '';
casper.then(function() {
url = casper.evaluate(function($) {
return $('.imgCol a').attr('href');
});
});
casper.then(function() {
this.open(url).then(function() {
var obsolete = this.evaluate(function($) {
return Boolean(($('*:contains("Obsolete")')).length);
});
if (obsolete) { this.then(scrapeObsolete); }
else { this.then(scrape); }
});
});
function scrapeObsolete() {
console.log('Scraping Product: ' + this.getCurrentUrl());
var o = this.evaluate(function ($) {
var old = +($('.prdctDescription td:contains("Catalog #")').next().html())
var replacement = $('.tabContHolder p:contains("replacement") a').html().replace(/.$/, '');
return {
old: old,
obsolete: true,
replacement: replacement
}
});
console.log('old: ' + o.old);
console.log('replacement: ' + o.replacement + '\n');
}
function scrape() {
// to be soon implemented
console.log('Scraping Product: ' + this.getCurrentUrl());
}
casper.run();
@gregorynicholas
Copy link

i'm assuming that jQuery.js sat inside of the same directory as this file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment