2011-12-10 4 views
2

HtmlAgilityPack을 사용하여 HTML에서 텍스트를 추출하려고합니다. 내 프로젝트에 HtmlAgilityPack을 추가했습니다. 그러나 본문 텍스트를 추출하려면 다음 코드를 시도했습니다.HtmlAgilityPack을 사용하여 WP7에서 HTML에서 텍스트 가져 오기

HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); 

// There are various options, set as needed 
htmlDoc.OptionFixNestedTags=true; 

// filePath is a path to a file containing the html 
htmlDoc.Load(filePath); 

// Use: htmlDoc.LoadXML(xmlString); to load from a string 

// ParseErrors is an ArrayList containing any errors from the Load statement 
if (htmlDoc.ParseErrors!=null && htmlDoc.ParseErrors.Count>0) 
{ 
    // Handle any parse errors as required 
} 
else 
{ 
    if (htmlDoc.DocumentNode != null) 
    { 
     HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body"); 

     if (bodyNode != null) 
     { 
      // Do something with bodyNode 
     } 
    } 
} 

및 프로젝트를 빌드 할 때 다음 오류가 나타납니다.

오류 1 'System.Xml.XPath.IXPathNavigable'형식이 참조되지 않은 어셈블리에 정의되어 있습니다. 어셈블리 'System.Xml.XPath, Version = 2.0.5.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35'에 대한 참조를 추가해야합니다. D : \ test \ test \ MainPage.xaml.cs 58

System.Xml 참조를 추가했음을 추가해야하며이 오류가 계속 발생합니다. 이 문제를 도와 주실 수 있습니까? 감사.

+0

전화로 HAP을 사용하면 구문 분석 된 HTML에서 물건을 찾기 위해 Linq2Xml을 사용해야합니다. –

+0

가능한 [WP7.5에 HTML 민첩성 팩 사용] (http://stackoverflow.com/questions/8454959/using-html-agility-pack-on-wp7-5) –

답변

8

감사합니다. Microsoft SDK의 상위 폴더에서 사용할 수있는 Silverlight 4.0 폴더에서 System.Xml.XPath에 대한 참조를 추가해야한다는 것을 알았습니다.

+0

실제로 배포를 시도해 봤나? 전화? –

+0

예, 정상적으로 작동했습니다. – Kartos

+1

이것은 Windows Phone 8의 측면에서 나에게 도움이되지 못했습니다. 어떤 단서가 있습니까? –

0

System.Xml에 대한 참조를 추가해야한다고 말합니다. XPath이 아닌 System.Xml.

1

전화로 HAP을 사용하는 경우 Linq2Xml을 사용하여 구문 분석 된 HTML에서 물건을 찾아야합니다. 그리고 소스 (HAPPhone)에서 전화 버전을 만들어야 할 수도 있습니다.

public void Hap() 
{ 
    HtmlWeb.LoadAsync("http://www.page.com", OnCallback);    
} 



private void OnCallback(object s, HtmlDocumentLoadCompleted htmlDocumentLoadCompleted) 
     {    
      var htmlDocument = htmlDocumentLoadCompleted.Document; 

      var test = htmlDocument.DocumentNode.Descendants("select").ToList(); 


      var test2 = (from h in htmlDocument.DocumentNode.Descendants("select") 
         where h.Attributes["id"].Value == "stateDropdown" 
         select h).FirstOrDefault().ChildNodes.ToList(); 
     } 
관련 문제