2011-10-30 7 views
0

私は1つの列にすべてのhtmlページを保存したテーブルを持っています。私はどのように私はこれを行うことができますhtmlagilityを使用してそのdivからdiv(およびその内容)をフェッチしたいです。私はURLからロードしたり、画面のスクレイピングをしたりしたくありません。Htmlagilityパックを使用してHTML文字列からdivを検索する

答えて

1
// Load your html 

HtmlDocument htmlDocument = new HtmlDocument(); 
htmlDocument.LoadHtml(html); 
// Find div with an id or you could use a class if you want 
var nodes = htmlDocument.DocumentNode.SelectNodes("//div[@id='myDivId']"); 
0

この解決策が見つかりました。

HtmlDocument doc = new HtmlDocument(); 
      doc.LoadHtml(@html); 

      HtmlNodeCollection tableRows = doc.DocumentNode.SelectNodes("//tr"); 

      string content = ""; 
      if (tableRows.Count > 1) 
      { 
       HtmlNode node = doc.DocumentNode.SelectSingleNode("//div[@class='account-detail']"); 
       content = node.InnerHtml; 
      } 

ありがとうございます。

関連する問題