Web Page Parsing - WP8 - HTMLAgilityPack

帅比萌擦擦* 提交于 2019-12-11 23:35:36

问题


I am actually trying to parse the content of this webpage, http://www.cryptocoincharts.info/v2/coins/show/tips

In particular I'd need to get the numbers, like "Current Difficulty", "Mined coins till now" etc

I am not actually sure how to do that, I actually located the section where my numbers are, yet I am not able to write the code to actually get those numbers out :(

Thanks in advance for any help!

EDIT: This is the code I have so far:

protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string htmlPage = "";
            using (var client = new HttpClient())
            {
                try
                {
                    htmlPage = await client.GetStringAsync("http://www.cryptocoincharts.info/v2/coins/show/tips");
                }
                catch (HttpRequestException exc) { }
            }

        HtmlDocument htmlDocument = new HtmlDocument();
        htmlDocument.LoadHtml(htmlPage);

回答1:


HttpClient client = new HttpClient();
var doc = new HtmlAgilityPack.HtmlDocument();
var html = await client.GetStringAsync("http://www.cryptocoincharts.info/v2/coins/show/tips");
doc.LoadHtml(html);

var result = doc.DocumentNode.SelectSingleNode("//table[@class='table table-striped']")
                .Descendants("tr")
                .Skip(1)
                .Select(tr => new
                {
                    Desc = tr.SelectSingleNode("td[1]").InnerText,
                    Val = WebUtility.HtmlDecode(tr.SelectSingleNode("td[2]").InnerText)
                })
                .ToList();


来源:https://stackoverflow.com/questions/22103379/web-page-parsing-wp8-htmlagilitypack

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