2016-11-20 89 views
-2

我正在尋找從barchart.com解析數據(每天一次)的方法(例如,此鏈接https://www.barchart.com/futures/quotes/HG * 0/all-futures#/ viewName = main) 。解析新的「barchart.com」網站

問題是,頁面代碼不包含我想要的值(我找不到在頁面上加載它的js腳本)。我的意思是關閉/開放/高價格的桌子。

我想最簡單的方法是使用表格右上角的「下載」按鈕從頁面下載excel文件(然後使用它)。但我也找不到下載鏈接,導致點擊事件也在某些腳本中處理。

我正在使用C#,但沒有要求代碼。任何想法和提示都將非常有用。謝謝。

回答

0

如果您在Web檢查器中檢查網絡選項卡,則會找到用於加載數據的URL。只需直接打電話,然後按照你的意願去做。這是一個jQuery示例(因爲我可以使用片段工具演示該概念),但使用WebClient.DownloadString()方法從C#調用它很簡單。

var url = 'https://core-api.barchart.com/v1/quotes/get?fields=symbol%2CcontractName%2ClastPrice%2CpriceChange%2CopenPrice%2ChighPrice%2ClowPrice%2CpreviousPrice%2Cvolume%2CopenInterest%2CtradeTime%2CsymbolCode%2CsymbolType%2ChasOptions&list=futures.contractInRoot&root=HG&meta=field.shortName%2Cfield.description&hasOptions=true&raw=1'; 
 

 
$('#data').load(url);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
Data: <br /> 
 
<textarea id="data" cols="50" rows="8"></textarea>

C#例如:

public static void DownloadString (string address) 
{ 
    WebClient client = new WebClient(); 
    string reply = client.DownloadString (address); 

    Console.WriteLine (reply); 
    return reply; 
} 

var url = 'https://core-api.barchart.com/v1/quotes/get?fields=symbol%2CcontractName%2ClastPrice%2CpriceChange%2CopenPrice%2ChighPrice%2ClowPrice%2CpreviousPrice%2Cvolume%2CopenInterest%2CtradeTime%2CsymbolCode%2CsymbolType%2ChasOptions&list=futures.contractInRoot&root=HG&meta=field.shortName%2Cfield.description&hasOptions=true&raw=1'; 

var data = DownloadString(url);