2016-05-12 8 views
1

HTMLは、私はラベルとTRタグ内のすべての番目とTDタグのデータを取得したいこのはどのように、HTMLの敏捷性パック

<tr> 
<th class="label">Brand</th> 
<td class="data">Dell</td> 
</tr> 
<tr> 
<th class="label">Series</th> 
<td class="data">Inspiron Touch</td> 
</tr> 
<tr> 
<th class="label">Color</th> 
<td class="data">Black & Red</td> 
</tr> 
<tr> 
<th class="label">Operating System</th> 
<td class="data">Windows 10 Home</td> 
</tr> 
<tr> 
<th class="label">Screen Size</th> 
<td class="data">15.6"</td> 
</tr> 
<tr> 
<th class="label">Touchscreen</th> 
<td class="data">Yes</td> 
</tr> 
<tr> 
<th class="label">Screen Resolution</th> 
<td class="data">3840 x 2160</td> 
</tr> 
<tr> 
<th class="label">Processor Type</th> 
<td class="data">Intel Core i7 6th Gen</td> 
</tr> 
<tr> 
<th class="label">Processor Speed</th> 
<td class="data">2.6 GHz</td> 
</tr> 
<tr> 
<th class="label">Processor Turbo</th> 
<td class="data">Up to 3.5 GHz</td> 
</tr> 
<tr> 
<th class="label">Processor Cache</th> 
<td class="data">6 MB</td> 
</tr> 
<tr> 
<th class="label">Processor Model</th> 
<td class="data">i7-6700HQ</td> 
</tr> 
<tr> 
<th class="label">RAM</th> 
<td class="data">16GB</td> 
</tr> 
<tr> 
<th class="label">RAM Type</th> 
<td class="data">DDR3L</td> 
</tr> 
<tr> 
<th class="label">Hard Disk Capacity</th> 
<td class="data">1TB + 128GB SSD</td> 
</tr> 
<tr> 
<th class="label">HDD Interface</th> 
<td class="data">SATA, SSD</td> 
</tr> 
<tr> 
<th class="label">HDD RPM</th> 
<td class="data">5400</td> 
</tr> 
<tr> 
<th class="label">Graphics</th> 
<td class="data">Nvidia Graphics</td> 
</tr> 
<tr> 
<th class="label">Graphics Detail</th> 
<td class="data">Nvidia GeForce GTX 960M</td> 
</tr> 

のようである最初の4のみブランドシリーズの色やオペレーティングシステムを使用してTR取得しますしかし、他のアイテムも同じですが、trの中に同じクラスとtdクラスがある場合は、これらのアイテムをhtml agility packを使用して取得する方法を教えてください。これらのアイテムをDBに挿入します。選択ノードを使用します。のみ、私はこれらのtrに私がこのコードを使用しているときに私はいつ

HtmlNodeCollection specsNode = null; 
      specsNode = doc.DocumentNode.SelectNodes("//tr']"); 
      foreach (HtmlNode node in specsNode) 
      { 
       string htmli = node.InnerHtml; 
       HtmlDocument doci = new HtmlDocument(); 
       doci.LoadHtml(htmli); 
    htmlNode node2 in doci.DocumentNode.SelectNodes("//td[@class='data']"){ 
node2.InnerText; 

私はfamilier wです今ではHAPですが、tr内のクラスは同じで、今はそれらをどうやって取得するのか分かりません。

+0

いくつかの他の項目をINCLUDE *ポストサンプルHTML trと同じthとtdクラスを持っている。また、これまでにHtmlAgilityPackを使って何を試しましたか? – har07

+0

@ har07質問を編集しました –

+0

@ har07毎回同じクラスがありますので、毎回最初に選択したメソッドを選択してください。2番目と3番目を取得する方法がわかりません –

答えて

1

私はuがここでやろうとしているのか分からないが、私は.Contains機能は、チェックのために、あなたの問題使用.Contains機能を解決する上でのuを助けるかもしれないと思い

string Result=html; 
htmldocument doc=new htmldocument(); 
doc.Loadhtml(Result); 
htmlnodecollection noden=null; 
noden=doc.DocumentNode.SelectNodes(""); 
if(Result.Contains("your brand")==true) 
{ 
//do something 
+0

ありがとうございますが、私はすでに.Containsを使用して解決しています –

関連する問題