iframe js 加载失败_Phantomjs无法加载iframe

I'm a newbie, recently started to use phantomjs with casperjs. I want to get info from an iframe but phantomjs fails to load it.

This is my script:

var casper = require('casper').create({

verbose: true,

logLevel: "debug",

waitTimeout: 20000,

retryTimeout: 100,

viewportSize: {

width: 1920,

height: 1080

},

pageSettings: {

"userAgent": 'Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1'

},

localToRemoteUrlAccessEnabled: true

});

casper.start();

casper.open('http://www.badboysbarber.ru/online');

casper.waitForSelector('.y-main-container', function() {

this.echo("Selector appeared.");

});

casper.then(function() {

this.capture('screen.png');

});

casper.run();

So, phantom throws an error (although selector is defined correctly):

[error] [phantom] Wait timeout of 20000ms expired, exiting.

Could somebody help me please? Maybe I'm doing something wrong? Thank you.

解决方案

An iframe loads a document inside another document. If you want to work with frames and use CasperJS to get data, you will probably need withFrame() in Casper.prototype.

The following script captures the raw HTML content of the first iframe in your main page:

var casper = require('casper').create({

viewportSize: {

width: 1920,

height: 1080

},

pageSettings: {

'userAgent': 'Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1'

},

localToRemoteUrlAccessEnabled: true

});

casper.start('http://www.badboysbarber.ru/online');

casper.withFrame(0, function () {

this.echo(this.getHTML()); // HTML code of the first iframe

});

casper.run();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值