phantomwebintro.js 622 B

123456789101112131415161718192021
  1. // Read the Phantom webpage '#intro' element text using jQuery and "includeJs"
  2. "use strict";
  3. var page = require('webpage').create();
  4. page.onConsoleMessage = function(msg) {
  5. console.log(msg);
  6. };
  7. page.open("http://phantomjs.org/", function(status) {
  8. if (status === "success") {
  9. page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
  10. page.evaluate(function() {
  11. console.log("$(\".explanation\").text() -> " + $(".explanation").text());
  12. });
  13. phantom.exit(0);
  14. });
  15. } else {
  16. phantom.exit(1);
  17. }
  18. });