2010-02-20 60 views
1

here,我試圖從每10分鐘間隔的股票報價中獲取數據。使用C的html解析問題#

我用WebClient下載頁面內容和解析我用正則表達式。它爲其他網址工作正常。對於特殊的URL,我的解析代碼不起作用。

我認爲這是javascript的問題,當我在瀏覽器中加載頁面後,加載頁面內容後,繪製數據需要一些額外的時間。可能是這個人正在使用這個頁面的一些客戶端腳本。誰能幫我請..........

+0

你想從那個網頁上得到什麼信息? – 2010-02-20 12:41:04

+0

嗨馬克,在該頁面我需要打開興趣值。 – Raghu 2010-02-20 13:08:36

回答

4

HTML Agility Pack會爲您節省大量的頭痛。 Try it而不是使用正則表達式來解析HTML。

對於它的價值,你鏈接到報價數據的確在Javascript代碼的頁面,檢查http://www.nseindia.com/js/getquotedata.jshttp://www.nseindia.com/js/quote_data.js

+0

+1同意,當然還有義務鏈接:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – 2010-02-20 12:46:15

+0

嗨溫科,我將遵循你的建議。感謝您的幫助...... – Raghu 2010-02-20 13:14:43

+0

你好Vinko,還有一個疑問,我已經下載了鏈接的內容,就像@Asad Butt所建議的那樣,當我看到這個String的來源時,沒有任何值) 在裏面。我認爲這些是使用JavaScript動態生成此報告的,這種情況是否可以通過HTML Agility Pack處理? – Raghu 2010-02-21 08:16:28

2

按@Vinko Vrsalovic答案,Html Agility pack是你的朋友。這裏是一個樣本

WebClient client = new WebClient(); 
    string source = client.DownloadString(url); 

    HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument(); 
    document.LoadHtml(source); 

    HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("//*[@href]"); 

    foreach (HtmlNode node in nodes) 
    { 
    if (node.Attributes.Contains("class")) 
    { 
    if (node.Attributes["class"].Value.Contains("StockData")) 
    {// Here is our info } 
    } 
    }