2013-04-11 182 views
3

我試圖讓HtmlAgilityPack與Windows 8 Metro應用程序(Windows應用商店應用程序)配合使用。我已經成功地在Windows控制檯應用程序(C#)中寫出了我需要的所有代碼,並且它完美地解析了我需要的HTML,並將我需要的所需字符串返回給我。HtmlAgilityPack和Windows 8 Metro應用程序

// 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\"]"); 

我的問題是與DocumentNode.SelectSingleNode調用。我收到以下錯誤:

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?)

我證實,我把所有的引用設置的確切方法,我在控制檯應用程序做同樣的,但我無法得到這個工作。根據HtmlAgilityPack twitter帳戶,在版本1.4.5中添加了對Windows 8 Metro/Windows Phone 8的支持。我再次檢查我的NuGet包管理器,並且我安裝了1.4.6。

在Windows 8應用程序的HtmlDocument中,我需要做些什麼來選擇節點XPath?任何建議將不勝感激。

謝謝!

編輯:任何人都可以幫我獲得與Linq查詢相同的結果,然後。我不確定我會怎麼做。

+0

請檢查[Metro版本和SelectNodes](https://htmlagilitypack.codeplex.com/discussions/359358)&[HtmlAgilityPack和Windows 8 winRT](http://stackoverflow.com/questions/12829137/htmlagilitypack-and -windows-8-winrt) – Xyroid 2013-04-11 06:04:13

+0

任何人都可以幫我用Linq查詢獲得相同的結果。我不確定我會怎麼做。 – 2013-04-11 06:08:47

回答

9

Html Agility Pack依靠.NET來實現XPATH。不幸的是,WinRT不支持XPATH,因此您在WinRT的Html Agility Pack中沒有與XPATH相關的任何內容。

+1

奇怪的是,如果HtmlAgilityPack聲稱支持Windows 8 Metro(即.NET WinRT配置文件),這個答案是正確的。我猜這個項目實際上並不支持Windows 8(Windows Store)應用程序,儘管它聲稱它。我其實並沒有在項目網站上看到這個聲明...... – 2013-04-11 16:11:27

+1

它確實支持WinRT,但是你必須使用XPATH以外的其他方法,比如Linq,Descendants等。 – 2013-04-11 16:47:34

+0

我想我有一個大腦屁,我正在讀WinRT作爲Windows RT,而不是WinRT .NET配置文件(儘管我正在考慮它)。 – 2013-04-11 16:50:14

相關問題