通过PhantomJs下载带有Knockout绑定的页面

问题描述 投票:0回答:1

我想用PhantomJs在Microsoft Virtual Academy上解析一个页面。例如this one。我可以加载它(请参阅result),但在下载的源代码中,我没有看到课程描述或其持续时间。

要下载我用过下一个方法的页面:https://gist.github.com/DotNetNerd/5635371

public string Grab(string url)
{
    var process = new System.Diagnostics.Process();
    var startInfo = new System.Diagnostics.ProcessStartInfo
    {
        WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
        UseShellExecute = false,
        RedirectStandardOutput = true,
        FileName = Config.PhantomJSPath,
        Arguments = string.Format("\"{0}\\{1}\" {2}", Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "index.js", url)
    };

    process.StartInfo = startInfo;
    process.Start();
    string output = process.StandardOutput.ReadToEnd();
    process.WaitForExit();

    return output;
}

和指数Js

var page = require('webpage').create(),
system = require('system');

page.onLoadFinished = function() {
  console.log(page.content);
    phantom.exit();
};
page.open(system.args[1]);

我应该配置phantomjs等待绑定生效还是PhantomJs根本不支持它?

c# knockout.js web-scraping phantomjs
1个回答
0
投票

最后,我决定在页面加载后等待5秒。它不能保证一切都会在这个时候加载,但对我有用。

Index.js已更新为:

var page = require('webpage').create(),
system = require('system');

page.onLoadFinished = function() {
    setTimeout(function () {
        console.log(page.content);
        phantom.exit();
}, 5000);

};
page.open(system.args[1]);
© www.soinside.com 2019 - 2024. All rights reserved.