简体   繁体   中英

Node.js and node phantom include jquery

My currently code:

var phantom = require('phantom');
var fs = require('fs');

phantom.create(function(ph) {

  return ph.createPage(function(page) {

    return page.open("http://www.example.com", function(status) {

      page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js', function(err) {

        return page.evaluate(function() {
          return $('#test').value();
        }, function(result) {
          console.log(result)
        });

      });

    });
  });
});

I'm trying to include jQuery into the page so everything is fine till I get to $() part where I get this error:

Undefined is not a constructor (evaluating $('#test').value())

If instead of $('#test').value() I try for example document.title everything works fine tho.

Are you sure you copied the correct error message it should be:

TypeError: 'undefined' is not a function (evaluating '$('#test').value()')

Anyway your problem is .value() as this is not a function provided by jQuery.
You are probably looking for .val() or .text() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM