简体   繁体   English

如何在没有WebBrowser控件的情况下“呈现” HTML

[英]How to “render” HTML without WebBrowser control

First at all - I don't know if "render" is the right word. 首先-我不知道“渲染”是否正确。 I like to get information from an website. 我喜欢从网站上获取信息。 At the moment therefore I use the WebBbrowser control. 因此,目前我使用WebBbrowser控件。 Now I like to use HttpWebRequests because I think, that's much faster and threading could be used more easily. 现在,我喜欢使用HttpWebRequests,因为我认为这要快得多,并且可以更轻松地使用线程。 But I can't use them, because the HTML-output string I receive from HttpWebRequest has got a lot of JavaScript inside from which the information, that I need, will be created. 但是我不能使用它们,因为我从HttpWebRequest接收的HTML输出字符串中包含很多JavaScript,可以从中创建所需的信息。 The web browser "renders" the JavaScript to readable HTML. Web浏览器将JavaScript“渲染”为可读的HTML。 How to do this step "by hand", so that I can use HttpWebRequests? 如何“手动”执行此步骤,以便可以使用HttpWebRequests?

I hope you understand, what I want. 我希望你明白我想要的。

因此,如果您需要javascript渲染引擎,建议您查看selenium项目。

I solved my problem with a project called Awesomium . 我通过一个名为Awesomium的项目解决了我的问题。 In this thread you will find all you need to get html with executed javascript. 在该线程中,您将找到获取具有已执行javascript的html所需的全部信息。 The "special part" is this one: “特殊部分”是这一部分:

var sourceVal = webView.ExecuteJavascriptWithResult( "document.getElementsByTagName('html')[0].outerHTML;" );

if ( sourceVal != null )
{
    using ( sourceVal )
    {
        html = sourceVal.ToString();
    }
}

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

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