HTML is:
<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. I am using this code to Get String of Div Area. 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. 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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.