Last active
August 29, 2015 14:11
-
-
Save sTiLL-iLL/ce31818dcb4ca71afaf3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 characters
/** | |
* Usage: phantomjs scrape.js URL [selector] | |
* selector defaults to `#content` | |
*/ | |
var page = require('webpage').create(), | |
system = require('system'); | |
if (system.args.length < 2 || system.args.length > 3) { | |
console.log('Usage: phantomjs scrape.js URL [selector]'); | |
console.log(' selector defaults to `#content`'); | |
phantom.exit(1); | |
} else { | |
page.open(system.args[1], function (status) { | |
if (status !== 'success') { | |
console.log('Unable to access network'); | |
} else { | |
var p = page.evaluate(function (selector) { | |
return document.querySelector(selector).innerHTML; | |
}, system.args[2] ? system.args[2] : "#content"); | |
console.log(p); | |
} | |
phantom.exit(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment