zoukankan      html  css  js  c++  java
  • C#中的GetElementsByClassName方法


    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
        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;
           
  • 相关阅读:
    Redis Cluter
    数据库设计范式
    kvm虚拟化
    架构前端
    集群架构
    初识shell编程
    网络知识
    Linux三剑客
    Linux磁盘管理
    高性能异步爬虫
  • 原文地址:https://www.cnblogs.com/c-x-a/p/6943338.html
Copyright © 2011-2022 走看看