RT…没ID,GetElementsByTagName不适合,干脆把GetElementsByClassName实现了得了…
public static class Spread
{
/// <summary>
/// 检索指定class的所有HtmlDocument对象
/// </summary>
/// <param name="doc"></param>
/// <param name="className"></param>
/// <returns></returns>
public static HtmlElement GetElementsByClassName(this HtmlDocument doc, string className)
{
HtmlElementCollection collection = doc.All;
//HtmlElementCollection collection = doc.Body.All;
HtmlElement html = doc.CreateElement("");
foreach (HtmlElement he in collection)
{
if (he.GetAttribute("classname") == className)
{
html.AppendChild(he);
}
}
return html;
}
}