2010-03-29 96 views
0

這裏是一個表,滿分5:解析HTML使用HTTP敏捷性包

<h3>marec - maj 2009</h3> 
<div class="graf_table"> 
<table summary="layout table"> 
    <tr> 
     <th>DATUM</th> 
     <td class="datum">10.03.2009</td> 
     <td class="datum">24.03.2009</td> 
     <td class="datum">07.04.2009</td> 
     <td class="datum">21.04.2009</td> 
     <td class="datum">05.05.2009</td> 
     <td class="datum">06.05.2009</td> 
    </tr> 
    <tr> 
     <th>Maloprodajna cena [EUR/L]</th> 
     <td>0,96000</td> 
     <td>0,97000</td> 
     <td>0,99600</td> 
     <td>1,00800</td> 
     <td>1,00800</td> 
     <td>1,01000</td> 
    </tr> 
    <tr> 
     <th>Maloprodajna cena [SIT/L]</th> 
     <td>230,054</td> 
     <td>232,451</td> 
     <td>238,681</td> 
     <td>241,557</td> 
     <td>241,557</td> 
     <td>242,036</td> 
    </tr> 
    <tr> 
     <th>Prodajna cena brez dajatev</th> 
     <td>0,33795</td> 
     <td>0,34628</td> 
     <td>0,36795</td> 
     <td>0,37795</td> 
     <td>0,37795</td> 
     <td>0,37962</td> 
    </tr> 
    <tr> 
     <th>Trošarina</th> 
     <td>0,46205</td> 
     <td>0,46205</td> 
     <td>0,46205</td> 
     <td>0,46205</td> 
     <td>0,46205</td> 
     <td>0,46205</td> 
    </tr> 
    <tr> 
     <th>DDV</th> 
     <td>0,16000</td> 
     <td>0,16167</td> 
     <td>0,16600</td> 
     <td>0,16800</td> 
     <td>0,16800</td> 
     <td>0,16833</td> 
    </tr> 
</table> 
</div> 

我要提取出值,其中表頭是DATUM和Maloprodajna以上的價格[EUR/L]。 我正在使用Agility HTML包。

this.htmlDoc = new HtmlAgilityPack.HtmlDocument(); 
this.htmlDoc.OptionCheckSyntax = true; 
this.htmlDoc.OptionFixNestedTags = true; 
this.htmlDoc.OptionAutoCloseOnEnd = true; 
this.htmlDoc.OptionOutputAsXml = true; // is this necessary ?? 
this.htmlDoc.OptionDefaultStreamEncoding = System.Text.Encoding.Default; 

我把這些數值拿出來有很多麻煩。 我開始:

var query = from html in doc.DocumentNode.SelectNodes("//div[@class='graf_table']").Cast<HtmlNode>() 
from table in html.SelectNodes("//table").Cast<HtmlNode>() 
from row in table.SelectNodes("tr").Cast<HtmlNode>() 
from cell in row.SelectNodes("th|td").Cast<HtmlNode>() 
select new { Table = table.Id, CellText = cell.InnerHtml }; 

但不能想出一個辦法來選擇僅在表頭的數據和Maloprodajna以上的價格[EUR/L]值。用where子句可以做到嗎?

然後,我與這兩個查詢結束:

var date = (from d in htmlDoc.DocumentNode.SelectNodes("//div[@class='graf_table']//table//tr[1]/td") 
        select DateTime.Parse(d.InnerText)).ToArray(); 

var price = (from p in htmlDoc.DocumentNode.SelectNodes("//div[@class='graf_table']//table//tr[2]/td") 
        select double.Parse(p.InnerText)).ToArray(); 

是否有可能這兩個查詢組合? 如何將其轉換爲lambda表達式? 我剛開始學習這些東西,我想知道它是如何做的,以便將來我不會有這些問題。

O,還有一個問題......是否有人知道任何圖形控件,因爲我必須在圖中顯示這些值。 我開始使用Microsoft Chart Controls,但我在設置時遇到問題。 所以,如果任何人有任何經驗,我想知道如何設置它,以便x軸將顯示所有值不是每秒...例如: 如果我有:10.03.2009,24.03.2009,07.04。 2009年,21.04.2009,05.05.2009,06.05.2009 它只顯示:10.03.2009,07.04.2009,05.05.2009,等。

我將數據綁定到圖表那樣:

chart1.Series["Series1"].Points.DataBindXY(date, price); 

我很多我的拳頭後的問題...呵呵,希望我不是模糊不清或東西。 感謝您的回覆!

回答

0

對於這樣的CodePlex項目,請考慮直接發佈您的問題到他們的討論板上。通常這是聯繫開發人員的最佳方式。