我只是想学习HTMLAgilityPack和XPath,试图从纳斯达克网站获取(HTML链接)公司列表;
在运行我的项目时,我遇到了关于xpath无法处理的异常,提示它是一个无效的令牌。
我不太确定出了什么问题,我尝试在上面的tr [*]部分中放置一个数字,但仍然出现相同的错误。
我已经看了一个小时了,有什么简单的解决方法吗?
谢谢
http://www.nasdaq.com/quotes/nasdaq-100-stocks.aspx
我目前有以下代码;
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
// Create a request for the URL.
WebRequest request = WebRequest.Create("http://www.nasdaq.com/quotes/nasdaq-100-stocks.aspx");
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Read into a HTML store read for HAP
htmlDoc.LoadHtml(responseFromServer);
HtmlNodeCollection tl = htmlDoc.DocumentNode.SelectNodes("//*[@id='indu_table']/tbody/tr[*]/td/b/a");
foreach (HtmlAgilityPack.HtmlNode node in tl)
{
Debug.Write(node.InnerText);
}
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
我使用了Chrome的XPath插件来获取XPath;
//*table[@id='indu_table']/tbody/tr[*]/td/b/a
在运行我的项目时,我遇到了关于xpath无法处理的异常,提示它是一个无效的令牌。
我不太确定出了什么问题,我尝试在上面的tr [*]部分中放置一个数字,但仍然出现相同的错误。
我已经看了一个小时了,有什么简单的解决方法吗?
谢谢