简体   繁体   中英

Why this simple script in CasperJS doesn't work on bestbuy.com

I'm doing some exercises with CasperJS and I'm stuck in a pretty simple exercise.

I don't know if bestbuy.com website blocks the connection in some way. I've tried some different websites and they just work fine.

The Title is not printed on the console and the phantomjs task doesn't exit from the task.

Here you have the simple script:

 var casper = require('casper').create({ verbose:true, logLevel:'debug', pageSettings:{ loadImages: true, loadPlugins: false, userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36' } }); var url = 'http://www.bestbuy.com/'; casper.start(url, function () { this.echo(this.getTitle()); }); casper.run(); 

Can somebody, please explain what is this happening?

Thanks :)

For some reason it looks like bestbuy might be blocking your useragent.

This works for me:-

var casper = require('casper').create({
  verbose:true,
  logLevel:'debug'
});

var url = 'http://www.bestbuy.com/';

casper.start(url, function () {
  this.echo(this.getTitle());
});

casper.run();

This outputs the title correctly

在此处输入图片说明

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