WPF WebBrowser 无法加载 Angular JS 网站的渲染 HTML [英] WPF WebBrowser fails to load rendered HTML of an Angular JS website

查看:22
本文介绍了WPF WebBrowser 无法加载 Angular JS 网站的渲染 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 WPF 应用程序,我想获取使用 Angular JS 技术的网站的渲染 HTML.这是我尝试过的:

I am working on a WPF aplication and I want to get the rendered HTML of a website that uses Angular JS technology. Here is what I've tried:

首先,我创建一个 WPF Web 浏览器控件:

First, I create a WPF Web Browser control:

private WebBrowser webBrowser;

然后我将其导航到我的目标网页:

Then I navigate it to my target web page:

var uri = new Uri("http://my-angualrjs-site.com", UriKind.RelativeOrAbsolute);
webBrowser.Navigate(uri);

在我的 WebBrowser 实例的 LoadCompleted 事件处理程序中,我将检索到的文档转换为 mshtml.HTMLDocument:

In the LoadCompleted event handler of my WebBrowser instance I cast the retrieved document to mshtml.HTMLDocument:

var doc = (mshtml.HTMLDocument) webb.Document;

我得到的只是页面的原始 HTML,而不是 Angular JS 从服务器处理和呈现的 HTML.我错过了什么吗?

And all I get is the raw HTML of the page, not the HTML processed and rendered by Angular JS from the server. Am I missing something?

推荐答案

我遇到了类似的问题,无法在控件中正确呈现有角度的页面.在遵循 Noseratios 回答之后,它呈现并运行良好.也许这也会帮助你:C# webbrowser Ajax 调用

I had a similar issue with not being able to get an angular page to render properly in the control. After following Noseratios answer it was rendering and working good. Maybe this would help you too: C# webbrowser Ajax call

简而言之,您需要为控件添加功能,使行为更接近 IE.

In short, you need to add features to the control to make the behavior closer to IE.

通过他的解决方案,您将能够使用以下代码:

With his solution you'll be able to use code such as:

SetBrowserFeatureControlKey("FEATURE_AJAX_CONNECTIONEVENTS", fileName, 1);

这篇关于WPF WebBrowser 无法加载 Angular JS 网站的渲染 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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