Skip to content

@3on /phantom.js
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Scraping bootstrap for phantom.js
var system = require('system');
var page = require('webpage').create();
var url = "http://www.boston.com/bigpicture/";
var scrap = function(){
var r = {};
r.imgCount = $('img.bpImage').length;
r.imgURL = [];
$('img.bpImage').each(function(){
r.imgURL.push($(this).attr('src'));
});
return JSON.stringify(r);
};
page.open(url, function(status) {
if(status !== 'success') {
throw "Page load issue " + status;
}
page.onError = function (msg, trace) {
console.error('error > ' + msg);
console.error(trace);
};
page.onAlert = function(msg) {
console.error('alert > ' + msg);
};
page.onConsoleMessage = function (msg, line, source) {
var l = (line !== undefined) ? ' @ line: ' + line : '';
console.error('> ' + msg + l);
};
window.setTimeout(function(){
page.includeJs("https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js", function() {
var res = page.evaluate(scrap);
console.log(res);
phantom.exit();
});
}, 1000);
});
@omidfi

Well written!
My problem is when I try to output an array like this: [[234.23,2342.12,"Hello"]] I always get the last string without quotation marks: [[234.23,2342.12,Hello]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.