Created
June 29, 2012 18:09
Revisions
-
qcom revised this gist
Jun 29, 2012 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -46,8 +46,6 @@ function scrapeObsolete() { var replacement = $('.tabContHolder p:contains("replacement") a').html().replace(/.$/, ''); return new Person (catalogNumber, true, replacement, null, null, null, productNumber); }); console.log(product); -
qcom revised this gist
Jun 29, 2012 . 1 changed file with 21 additions and 9 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,20 @@ var skus = [113247,113248,113249]; var sku = [113247]; function Product(catalogNumber, obsolete, replacement, overview, features, specs, productNumber) { this.catalogNumber = catalogNumber; this.obsolete = obsolete; this. replacement = replacement; this.overview = overview; this.features = features; this.specs = specs; this.productNumber = productNumber; } var casper = require('casper').create({ clientScripts: ['jQuery.js'] }); casper.start('http://bradyid.com', function() { this.fill('form[action="/bradyid/catalog/siteSearchResultsView.do"]', { 'searchTerms': sku}, true); }); @@ -26,19 +40,17 @@ casper.then(function() { function scrapeObsolete() { console.log('Scraping Product: ' + this.getCurrentUrl()); var product = this.evaluate(function ($) { var catalogNumber = +($('.prdctDescription td:contains("Catalog #")').next().html()) var productNumber = +($('.prdctDescription td:contains("Product #")').next().html()) var replacement = $('.tabContHolder p:contains("replacement") a').html().replace(/.$/, ''); return new Person (catalogNumber, true, replacement, null, null, null, productNumber); this.echo('ugh'); this.echo(person); }); console.log(product); } function scrape() { -
qcom created this gist
Jun 29, 2012 .There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ 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();