C# 借助类名获取Div之间的字符串
HTML是:C# 借助类名获取Div之间的字符串,c#,html,time,C#,Html,Time,HTML是: <div class="topheader-left common-txt" style="color: #ffffff;vertical-align:top;padding-top:3px"> Sunday, April 28, 2013 | 08:07:07 PM </div> 配置
<div class="topheader-left common-txt" style="color: #ffffff;vertical-align:top;padding-top:3px">
Sunday, April 28, 2013 | 08:07:07 PM
</div>
配置了HTML敏捷包。现在代码是什么
我希望使用专门构建的HTML解析器(如配置的(XPath)或(jQuery选择器语法)HTML Agility Pack)可以更轻松地实现这一点。现在代码是什么。
HtmlElementCollection theElementCollection = default(HtmlElementCollection);
theElementCollection = webBrowser1.Document.GetElementsByTagName("div");
foreach (HtmlElement curElement in theElementCollection)
{
if (curElement.GetAttribute("class").ToString() == "topheader-left common-txt")
{
MessageBox.Show(curElement.GetAttribute("InnerText"));
}
}
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
var innerText = doc.DocumentNode
.SelectSingleNode("//div[@class='topheader-left common-txt']")
.InnerText;
DateTime time = DateTime.ParseExact(WebUtility.HtmlDecode(innerText).Split('|')[1].Trim(),
"hh:mm:ss tt",
CultureInfo.InvariantCulture);