Usage:
phantomjs apify-tester.js
var page = require('webpage').create(); | |
page.onConsoleMessage = function(msg, lineNum, sourceId) { | |
console.log('CONSOLE: ' + msg); | |
}; | |
page.open('https://seneweb.senegence.com/us/products/anti-aging/collagen-night-pak/', function() { | |
page.includeJs("https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js", function() { | |
page.evaluate(function() { | |
// SCRAPER LOGIC GOES HERE | |
function pageFunction(context) { | |
var price = context.jQuery('#p-font-price span.p-font-price').text().trim(); | |
console.log("price: " + price); | |
return { | |
'foo': 'bar', | |
'price': price | |
}; | |
} | |
var result = pageFunction({ | |
request: { | |
label: '', // label of actual url | |
url: window.location.href | |
}, | |
willFinishLater: function () { console.log('(willFinishLater)', arguments) }, | |
finish: function () { console.log('(finish)', arguments) }, | |
enqueuePage: function () { console.log('(enqueuePage)', arguments) }, | |
skipOutput: function () { console.log('(skipOutput)', arguments) }, | |
skipLinks: function () { console.log('(skipLinks)', arguments) }, | |
jQuery: $ | |
}); | |
console.log('Result: ' + JSON.stringify(result)); | |
}); | |
phantom.exit(); | |
}); | |
}); |