I took an example from http://phantomjs.org/page-automation.html because I need to press a button on JS site before scraping.
var page = require('webpage').create();
page.open('http://www.sample.com', function() {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
page.evaluate(function() {
$("button").click();
});
phantom.exit()
});
});
But when I run this code, I get this error:
work7.rb:5: `$(' is not allowed as a global variable name
work7.rb:5: syntax error, unexpected end-of-input $("button").click();
Is PhantomJS required properly?
var page = require('webpage').create();
page.open('http://example.com', function(status) {
});
It doesn't work!
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- webpage (LoadError)
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require'
from work7.rb:3:in '
What am I doing wrong?