I am trying to use CasperJS to scrape a website that has dynamic content and am failing so far. The website uses a couple of js libaries(e.g. Prototype) to use autocomplete to create content. I am therefore trying to insert some values and trigger events to set off the content creation. Inserting and triggering events works fine, but no content is created.
I am new to CasperJS and found that it has problems with relative paths to the libaries. I suspect that my problem arises from the libaries not loading properly in my page environment. I therefore tried to use injectJs
to inject them like this
// ... create casper and do some other stuff
casper.then(function() {
this.echo(this.page.injectJs('http://www.my-website.com/path/to/js1')); this.echo(this.page.injectJs('http://www.my-website.com/path/to/js2')); });
Unfortunately this returns false for both of the functions. The path to the script is correct, where else could be the root of this problem?
Thank you very much for any help.
I do not believe CasperJS can handle HTTP requests to inject scripts. This is weird because they actually show this in their FAQ on including jQuery. However, that same FAQ says the following:
You can't inject scripts using the HTTP protocol, you actually have to use a relative/absolute filesystem path to the script resource.
Just to double check, I tried it myself using Mac OS X and your above code. The results of echo were false
when using a file over http and true
when it was local.
this is how I Inject Jquery in Casperjs script
casper.options.clientScripts = ["jquery-3.2.1.min.js"]
Jquery file should be on same directory where casperjs script exisit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With