Reputation: 945
I'm trying out PhantomJS and wanted to use it to extract content from a webpage. However, I cannot inject jQuery using the following code.
console.log('SSL support = ', require('system').isSSLSupported);
var page = require('webpage').create();
console.log('page created');
page.open('https://www.google.com/#q=my+test+query', function() {
console.log('page opened');
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js", function() {
console.log('jQuery injected');
phantom.exit();
});
});
When I run the code, I see an error
C:\Users\royshi\SkyDrive\Developer\Crawler>phantomjs test.txt
SSL support = true
page created
page opened
TypeError: 'null' is not an object (evaluating 'document.body.appendChild')
http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js:1
^C
C:\Users\royshi\SkyDrive\Developer\Crawler>
My code is not too different from the example provided by PhantomJS. Wondering what could be wrong here.
EDIT:
It seems there is something wrong with the URL I used in the above example (i.e. "https://www.google.com/#q=my+test+query"). The code works for another URL: https://www.google.com/:
C:\Users\royshi\SkyDrive\Developer\Crawler>phantomjs test.txt
SSL support = true
page created
page opened
jQuery injected
C:\Users\royshi\SkyDrive\Developer\Crawler>
Wondering what's wrong with the URL "https://www.google.com/#q=my+test+query".
Upvotes: 3
Views: 1689