【发布时间】:2018-06-09 12:06:53
【问题描述】:
我想使用 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;
}
和 IndexJs
var page = require('webpage').create(),
system = require('system');
page.onLoadFinished = function() {
console.log(page.content);
phantom.exit();
};
page.open(system.args[1]);
我应该将 phantomjs 配置为等到绑定生效还是 PhantomJs 根本不支持它?
【问题讨论】:
-
从未尝试直接使用 PhantomJS,但尝试使用 Selenium 的 PhantomJSDriver。您下载的源代码不会显示您的期望,因为虚拟学院网站是通过 javascript 创建网站的。使用 Selenium,您可以使用其方法获取网站的大部分详细信息。
-
我使用 PhantomJs 下载页面,其中内容填充了 JS,并且运行良好。但是我还没有尝试过淘汰赛。你有使用 Selenium 的 PhantomJsDriver 下载此类页面的成功经验吗?
-
in the downloaded source code I don't see the description of the course or its duration.应该是AJAX下载的吧。 -
@Artiom 是的。用于导航、测试和网页抓取网站的出色工具。
-
@Artiom 观看这个 youtube 视频youtube.com/watch?v=1oCm6S5zGdE
标签: c# knockout.js web-scraping phantomjs