Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

c# - HtmlAgilityPack & Windows 8 Metro Apps

I'm trying to get HtmlAgilityPack to work with Windows 8 Metro Apps (Windows Store Apps). I've successfully written out all the code I need in a Windows Console App (C#) and it works perfectly for parsing the HTML I need and returning me the required string I need.

// Create a new HtmlDocument and load the incoming string
        HtmlDocument menu = new HtmlDocument();
        menu.OptionUseIdAttribute = true;
        menu.LoadHtml(response);

        HtmlNode nameToRemove = menu.DocumentNode.SelectSingleNode("//*[@id="maincontent_0_contentplaceholder_0_lblHall"]");

My problem is with the DocumentNode.SelectSingleNode call. I'm getting the following error:

Error 2 'HtmlAgilityPack.HtmlNode' does not contain a definition for 'SelectSingleNode' and no extension method 'SelectSingleNode' accepting a first argument of type 'HtmlAgilityPack.HtmlNode' could be found (are you missing a using directive or an assembly reference?)

I'm confirmed that I have all of the references setup the exact same way I did in the Console Application but am unable to get this to work. According to the HtmlAgilityPack twitter account, support for Windows 8 Metro/Windows Phone 8 was added in version 1.4.5. I'm double checked my NuGet Package Manager and I have 1.4.6 installed.

Is there something special that I need to do to select a node by XPath in an HtmlDocument in a Windows 8 App? Any suggestions would be highly appreciated.

Thanks!

Edit: Can anyone help me get the same results with a Linq query then. I'm not sure how I would go about it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...