zoukankan      html  css  js  c++  java
  • Winform webbrowser 隐藏 html 元素

    目的:用webbrowser打开网页,并隐藏网页上某个html元素

    1.如果已知元素ID,比较好办

    直接使用webbrowser1.Document.getElementById("id")获取元素,并修改属性

    1 HTMLDocument thedocument = WebBrowser.document.all; 
    2 HTMLElement theelement = thedocument.getElementById(""); //这里找你要藏的东西的ID; 
    3 theelement.setAttribute("visible",false); 
    4 或者
    5 HtmlElement htm = webBrowser1.Document.GetElementById("控件ID"); 
    6 htm.OuterHtml = ""; 

    2.未知元素ID,根据Name获得元素,然后筛选出所需元素隐藏

     1 HtmlElementCollection opts = webBrowser1.Document.GetElementsByTagName("table");
     2             if (opts.Count > 0)
     3             {
     4                 foreach (HtmlElement ele in opts)
     5                 {                 
     6                     if (ele.GetAttribute("class") == "a3")
     7                     {
     8                         //opts[0].InnerHtml = ""; /*低版本IE不适用*/
     9                         opts[0].Style = "display:none";
    10                     }
    11                 }
    12              
    13             }

     3.隐藏子元素

     1   HtmlElement ele = webBrowser1.Document.GetElementById("List");
     2                     HtmlElementCollection List= ele.Children[0].Children;
     3                     if (List.Count > 0)
     4                     {
     5                         foreach (HtmlElement b in List)
     6                         {
     7                             if (b.Children[1].GetAttribute("value") == "xxx")
     8                             {
     9                                 b.Style = "display:none";            
    10                             }
    11                         }
    12                     }
  • 相关阅读:
    Aviator
    Docker是什么
    vulnhub--SickOs1.1
    vulnhub--HackInOS
    本地浏览器远程访问服务器tensorboard(MobaXterm)
    dogecoin
    python多进程
    gpu
    python调用父类(超类)
    linux更改终端显示颜色(用户名颜色等)
  • 原文地址:https://www.cnblogs.com/yt1219787097/p/4944916.html
Copyright © 2011-2022 走看看