简体   繁体   English

捕获JavaScript生成的内容

[英]Capture JavaScript generated content

The web page is using JavaScript to put content on the page, so then I got plain HTML there is no data on the page. 网页使用JavaScript在页面上放置内容,因此我得到了纯HTML,页面上没有数据。 I need somerthing that will not only read the HTML, but also will execute and apply JavaScript to DOM, and only then return result as HTML text. 我需要的东西不仅可以读取HTML,还可以执行JavaScript并将其应用于DOM,然后将结果作为HTML文本返回。

The task is exactly same as in this question , but I'm looking a solution for .NET. 任务与此问题完全相同,但我正在寻找.NET的解决方案。

I'll be surprised if you find anything like that for .NET. 如果您为.NET找到类似的东西,我会感到惊讶。 I would use PhantomJS to open the page and interact with the DOM. 我将使用PhantomJS打开页面并与DOM交互。 It's a highly scriptable headless WebKit browser and will do exactly what you want with ease. 这是一个高度可编写脚本的无头WebKit浏览器,可以轻松轻松地实现您想要的一切。 See How to print html source to console with phantomjs for an example. 有关示例,请参见如何使用phantomjs打印html源以进行控制台

var page = require('webpage').create();
page.open('http://google.com', function () {
    console.log(page.content);
    phantom.exit();
});

You'll have to install PhantomJS and then launch a separate process to run your script, but PhantomJS will probably do a much better job than anything you can find written for .NET. 您必须安装PhantomJS,然后启动一个单独的进程来运行脚本,但是PhantomJS可能会比为.NET编写的任何内容做的更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM