如何在 Windows Phone 7 中解析 HTML 页面数据? [英] How to parse HTML page data in Windows Phone 7?

查看:24
本文介绍了如何在 Windows Phone 7 中解析 HTML 页面数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Windows Phone 7 应用程序中执行以下两个任务.

I want to do the below two tasks In Windows Phone 7 application.

1.导航到一个网页(例如http://www.FlightsInd.com)并获取HTML页面数据.我希望确保所有文档数据都已完全下载.

1.Navigate to a web page (e.g.http://www.FlightsInd.com) and get the HTML page data.I wnat to ensure that all the Document data is completely downloaded.

在 C#.Net 中,我使用以下代码执行此操作:

In C#.Net i am doing this using below code:

WebBrowser objWB = new WebBrowser();
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
objWB.Navigate("http://www.FlightsInd.com")

这里一旦 DocumentCompleted 事件被触发,就意味着该请求中的所有数据都被下载.

here once the DocumentCompleted event is fired it means all the data in that request is downloaded.

2.解析 HTML 页面元素数据.

2.Parse HTML page elements data.

在 C#.Net 中,我使用以下代码执行此操作.

In C#.Net i am doing this using below code.

       doc = webBrowser1.Document;
       btnElem = doc.GetElementById(streleid);

任何人都可以帮助我提供上述两个实现的等效类/代码吗?

Can anyody help me with the equivalent classes/code for the above two implementations ?

推荐答案

使用 WebBrowser Windows Phone 控件

导航到您的页面

browser.Navigate(new Uri("http://www.FlightsInd.com"));

了解导航已完成且内容已加载

WebBrowser.导航事件

WebBrowser.LoadCompleted 事件 - 在 WebBrowser 控件加载内容后发生.

WebBrowser.LoadCompleted Event - Occurs after the WebBrowser control has loaded content.

WebBrowser.NavigationFailed Event - 跟踪导航失败

WebBrowser 类事件按以下顺序引发:Navigating、Navigated 和 LoadCompleted.

The WebBrowser class events are raised in the following order: Navigating, Navigated, and LoadCompleted.

获取Html源

WebBrowser Windows Phone 控件包含将当前显示在 WebBrowser 控件中的 HTML 内容的源代码保存为字符串的特殊功能:

WebBrowser Windows Phone control contains special function to save the source for the HTML content currently displayed in WebBrowser control as a string:

string html = browser.SaveToString();

解析Html

查看 HTML 敏捷包

什么是解析 html 的最佳方法C#?

解析 HTML 字符串

附注.或者您可以使用webBrowser.InvokeScript (C#) 结合 js eval 调用任何可以在其中使用 window.external.notify 的 js 命令将结果传回到 C#.

PS. Alternatively you can use webBrowser.InvokeScript (C#) with combination of js eval to invoke any js command which can use window.external.notify inside it to pass results back to C#.

这篇关于如何在 Windows Phone 7 中解析 HTML 页面数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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