HtmlAgility:no contents appeared (C#,UWP)

后端 未结 2 788
我寻月下人不归
我寻月下人不归 2021-01-23 10:39

i tried to use htmlagilitypack to parse a table,after i ve done i realized that i forgot to prove if htmlagility part works or not. ... and its obvious it doesnt work i also did

相关标签:
2条回答
  • 2021-01-23 10:46

    Firstly, the third party package Html Agility Pack you are using currently is not supported in universal app. Please use HtmlAgilityPack for .NET Core 1.4.9.2 which is supported in universal app.

    Secondly, the parameter of the method htmlDoc.LoadHtml(string html) is not the Uri of html site, but the html content which can be got from a webrequest's response.

    So the right code should be as followings:

    WebRequest request = HttpWebRequest.Create("http://www.eurogymnasium-waldenburg.de/egw_content/Stunden_Vertretungsplan/home.html");
    WebResponse response = await request.GetResponseAsync();
    Stream stream = response.GetResponseStream();
    var result = "";
    using (StreamReader sr = new StreamReader(stream))
    {
        result = sr.ReadToEnd();
    }
    HtmlDocument htmlDoc = new HtmlDocument();
    htmlDoc.LoadHtml(result);
    var node = htmlDoc.DocumentNode.SelectSingleNode("/html/body[@class='ui-widget']/div[@id='main']/div[@id='vplan']/div[@id='bereichaktionen']");
    

    And I also upload the complete project CHtmlAgility to github you can download for testing.

    0 讨论(0)
  • 2021-01-23 10:59

    HtmlAgilityPack for UWP (also WinRT and other similar tech) doesn't support XPath. Answer from the man behind HtmlAgilityPack himself https://stackoverflow.com/a/15941723/5562523

    The Html Agility Pack relies on .NET for the XPATH implementation. Unfortunately, WinRT doesn't support XPATH, so you don't have anything related to XPATH in Html Agility Pack for WinRT.

    0 讨论(0)
提交回复
热议问题