2 일 동안 고생했습니다. .NET 4.5 winforms 프로젝트에서 C# 및 HtmlAgilityPack을 사용하여 웹 사이트에서 데이터를 추출합니다 (추출 할 필드는 $ flow 및 B/S 비율). 나는 (흐름 :/n/t/t/t; 흐름 245 M 대신에) 나는 가치가 없다. 웹 페이지의 값을 보면서을 쿼리 할 때 왜 아무 값도 얻지 못합니다. 다른 사람이 노드의 이유를 찾았는지보고 싶습니다. = null 쿼리 결과. 다음은 쿼리 된 웹 페이지의 URL입니다. http://finance.avafin.com/tradeFlow?type=BS_RATIO&date=06%2F14%2F2013&alertId=0&symbol=spy§orId=0&industryId=0값을 반환하지 않는 HtmlAgilityPack 쿼리
위의 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 문서가 올바르게로드됩니다. –