How to parse HTML page data in Windows Phone 7?

穿精又带淫゛_ 提交于 2019-12-03 20:56:17
Sergei Grebnov

Use WebBrowser Windows Phone control

To Navigate to your page

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

To understand that navigation completed and content is loaded

WebBrowser.Navigated Event

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

WebBrowser.NavigationFailed Event - to track navigation failures

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

To get Html source

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();

To parse Html

Look at HTML Agility Pack

What is the best way to parse html in C#?

Parsing HTML String

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#.

If I get your question right, you can use web browser isBusy property to track if its still downloading data and sleep while its still busy.

For parsing html document you can use NSoup library to parse the html just like jQuery. Its a port from java's JSoup library. http://www.developerfusion.com/project/98472/nsoup/

Syntax explained here: http://jsoup.org/cookbook/extracting-data/selector-syntax

If you own the webpage you are navigating to, you can use window.external.notify(document.documentElement.innerHTML) in your javascript to pass the document html to native layer. Then you would catch the value in your native code using ScriptNotify.

A little more complex, but if you don't own the webpage, you could host your own webpage, open an iframe with the original page, and get the html from the iframe.

See here for more info on window.external.notify: http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.scriptnotify(v=vs.95).aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!