HTML:
<strong>Capture Date/Time:</strong> August 1, 2012 1:05:00 PM EST<br>
<strong>Instructor:</strong> Ash<br>
<strong>Instructor Email:</strong> email@email.com<br>
<strong>Course ID:</strong> Course321<br>
我将如何获取每个强节点右侧的文本?
例如,为了获取课程 ID,我最终得到了一个字符串“Course321”。
代码:
private string getCourseID()
{
foreach (HtmlAgilityPack.HtmlNode strong in htmlDoc.DocumentNode.SelectNodes("//strong"))
{
string innerText = strong.InnerText;
if (innerText.Contains("Course ID"))
{
//select the outer text
//return outertext;
}
}
}
当前代码:
private string getCourseID()
{
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
string value = "Error";
foreach (HtmlAgilityPack.HtmlNode strong in htmlDoc.DocumentNode.SelectNodes("//strong"))
{
string innerText = strong.InnerText;
if (innerText.Contains("Course ID"))
{
HtmlAgilityPack.HtmlNode sibling = strong.SelectSingleNode("following-sibling::text()");
value = sibling.InnerText.Trim();
MessageBox.Show(value);
}
}
return value;
}