一直在掙扎2天。我在.NET 4.5 winforms項目中使用C#和HtmlAgilityPack從網站提取數據(我想提取的字段是$ flow和B/S比率)。 我到達現場(流量:/ n/t/t/t;而不是流量245 M),但我沒有任何價值。 我不知道爲什麼我查詢時我沒有得到任何價值,而我看到網頁中的值。想查看是否有其他人發現我的查詢結果= null的原因。 這是athe查詢網頁的網址:http://finance.avafin.com/tradeFlow?type=BS_RATIO&date=06%2F14%2F2013&alertId=0&symbol=spy§orId=0&industryId=0HtmlAgilityPack查詢返回沒有值
我使用上面的url作爲查詢。
請注意,我使用了下面的方法,但在另一個網頁上使用了不同的查詢,它工作,有一些不適用於當前查詢的問題,或者我懷疑當前網頁的字段模糊。
使用方法:
/// <summary>
/// Gets the data.
/// </summary>
/// <param name="url"> The URL. </param>
/// <returns> </returns>
public List<string> GetFlowData(string url)
{
// ('//a[contains(@href, "genre")]')
// <td class=" sorting_1">137.27B</td>
//*[@id="tf_data"]/tbody/tr[1]/td[8] // this is the xpath as seen in navigator for first value => I get no value when used as a query => (nodes = null)
//*[@id="tf_data"]/tbody/tr[1]/td[9] // this is the xpath as seen in navigator for second value => I get no value when used as a query => (nodes = null)
// //td[@class=''] => nodes null too
// I see the b/s ratio node in body but no value /n/ttt instead using [@id='tf_data']/tbody
var nodes = LoadHtmlDoc(url, "//*[@id='tf_data']/tbody");
List<string> tickers = new List<string>();
if (nodes == null)
{
return new List<string> { "Ticker not available" };
}
int i = 0;
foreach (var v in nodes)
{
i++;
MessageBox.Show(v.InnerText + " " + i.ToString());
//// The placement of the data containing bought/sold ratio
//if (i == 7)
//{
// tickers.Add(v.InnerText);
//}
//// The placement of the data containing $ Flow
//if (i == 8)
//{
// tickers.Add(CleanFlowData(v.InnerText));
//}
}
return tickers;
}
我做了loadhtml,它工作正常,它正確加載html文檔 –