Phantomjs无法加载iframe [英] Phantomjs can't load iframe

查看:627
本文介绍了Phantomjs无法加载iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,最近开始使用phaperomjs和casperjs。我想从iframe获取信息,但是phantomjs无法加载它。

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.

这是我的脚本:

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.

推荐答案

iframe 将文档加载到另一个文档中。如果你想使用框架并使用CasperJS来获取数据,你可能需要 withFrame() in Casper.prototype

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.

以下脚本捕获主页中第一个 iframe 的原始HTML内容:

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();

这篇关于Phantomjs无法加载iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆