挣扎了2天。我在 .NET 4.5 winforms 项目中使用 C# 和 HtmlAgilityPack 从网站中提取数据(我要提取的字段是 $ 流和 B/S 比率)。我到达现场(流量:/n/t/t/t;而不是流量 245 M)但我没有任何价值。我不知道为什么当我在网页中看到值时查询时没有得到任何值。想看看其他人是否找到了我的查询结果节点=null的原因。这是查询网页的网址:http: //finance.avafin.com/tradeFlow? type=BS_RATIO&date=06%2F14%2F2013&alertId=0&symbol=spy§orId=0&industryId=0
我使用上面的 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;
}