2012-11-18 23 views
-1

文本的值モhtml正文內容 作爲字符串 我怎樣才能使用蘭巴達語法元素中提取或<table><td> text/html的?提取在此代碼變種<code>TempTxt</code>從HTML源文件

public string ExtractPageValue(IWebDriver DDriver, string url="") 
    { 
     if(string.IsNullOrEmpty(url)) 
     url = @"http://www.boi.org.il/he/Markets/ExchangeRates/Pages/Default.aspx"; 
     var service = InternetExplorerDriverService.CreateDefaultService(directory); 
     service.LogFile = directory + @"\seleniumlog.txt"; 
     service.LoggingLevel = InternetExplorerDriverLogLevel.Trace; 

     var options = new InternetExplorerOptions(); 
     options.IntroduceInstabilityByIgnoringProtectedModeSettings = true; 

     DDriver = new InternetExplorerDriver(service, options, TimeSpan.FromSeconds(60)); 
     DDriver.Navigate().GoToUrl(url); 
     var TempTxt = DDriver.PageSource; 
     return "";//Math.Round(Convert.ToDouble(TempTxt.Split(' ')[10]),2).ToString(); 

    } 

回答

1

如果你是開放的嘗試HtmlAgilityPack

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); 
doc.LoadHtml(html); 

var table = doc.DocumentNode.SelectNodes("//table/tr") 
       .Select(tr => tr.Elements("td").Select(td => td.InnerText).ToList()) 
       .ToList(); 
+1

感謝L.B幫了我很多。 – LoneXcoder