2013-01-17 33 views
0

我使用C#和敏捷包刮一个网站,但结果我变得不同于我在萤火虫中看到的。我想这是因为该网站正在使用一些Ajax。试图在C上刮敏捷网页#

// The HtmlWeb class is a utility class to get the HTML over HTTP 
HtmlWeb htmlWeb = new HtmlWeb(); 
// Creates an HtmlDocument object from an URL 
HtmlAgilityPack.HtmlDocument document = htmlWeb.Load("http://www.saxobank.com/market-insight/saxotools/forex-open-positions"); 
// Targets a specific node 
HtmlNode someNode = document.GetElementbyId("href"); 
// If there is no node with that Id, someNode will be null 
richTextBox1.Text = document.DocumentNode.OuterHtml; 

有人可以告诉代码如何正确地做到这一点导致我回来只是纯html。我寻找的是一个

div id= "ctl00_MainContent_PositionRatios1_canvasContainer" 

任何想法?

回答

0

如果的ID,然后用它 - href是一个属性,而不是id的名称。

HtmlNode someNode = 
    document.GetElementbyId("ctl00_MainContent_PositionRatios1_canvasContainer"); 

这将是DIV与该ID。

然后可以选择任何a子节点,并利用其节点的href属性:

var href = someNode.SelectNodes("//a")[0].Attributes["href"].Value;