[英]Getting String between Div with the help of Class Name
HTML is: 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>
I need the value of time which is 08:07:07 which i will convert into time. 我需要时间值08:07:07它将转换为时间。 I am using this code to Get String of Div Area.
我正在使用此代码来获取Div区域的字符串。 for getting substring.
用于获取子字符串。 Why this is not working?
为什么这不起作用?
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"));
}
}
HTML Agility Pack configured.
HTML Agility Pack已配置。 what will be the code now.
现在的代码是什么。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.