2012-08-04 6 views
0

저는이 시간이 오래되었습니다.Windows Phone HtmlAgilityPack이 지정한 클래스에서 노드를 가져 오지 못했습니다.

<a href="http://www.sample.com/samplepath/" class="sample_model">Test</a> 

내가 디버깅이 코드를 한 단계 때 내가 노드

var imagediv = (from imgnode in document.DocumentNode.Descendants() 
           where imgnode.Name == "a" && 
           imgnode.Attributes["class"].Value == "sample_model" 
           select imgnode).FirstOrDefault(); 

를 검색하기 위해 다음과 같은 C# 코드를 사용하고,이 범위를 벗어나 :이 HTML을 가지고있다. 나는 내가 원하는 것을 얻지 못한다. 나는 오류를 얻지 않는다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

0

이것은하지 않았다, 불행하게도

var imagediv = (from imgnode in document.DocumentNode.Descendants("a") 
       where imgnode.Attributes["class"].Value == "sample_model" 
       select imgnode).FirstOrDefault(); 

하거나

var imagediv = document.DocumentNode.SelectSingleNode("//a[@class='sample_model']"); 
+0

을 작동합니다. 첫 번째 코드에서는 범위가 좁아집니다. (아래 코드를 따라 가면서 다음 중괄호로 건너 뜁니다.) 두 번째 코드 조각 인 VS는 HtmlAgilityPack에 SelectSingleNode에 대한 정의가 없다고 말합니다. 나는 WP V1.4.5.0에 대해 HtmlAgilityPack을 사용하고 있습니다. – user1576422

+0

@ user1576422 게시하기 전에 테스트를하고 위의 코드는'a' 태그를 반환합니다. ('SelectSingleNode'는 WP에 대한 HAP에는 존재하지 않을 수도 있습니다) –

관련 문제