本帖最后由 Artince 于 2009-09-26 08:47:01 编辑

解决方案 »

  1.   

    HtmlElement he = wb.Document.All["regMarketForm"];
                    for (int i = 0; i < he.All.Count; i++)
                    {
                        if (he.All[i].GetAttribute("属性").IndexOf("值") >= 0)
                        {
                        }
                    }
      

  2.   

    编列表单里的所有超链接:
    HtmlElementCollection hc = this.webBrow.Document.Links;
                foreach (HtmlElement he in hc)
                {
                    if (he.GetAttribute("href").Contains("OfficeDocBrower.aspx"))
                    {
                        //he.SetAttribute("target", "");
                        //he.OuterHtml.Replace("target=_blank", "");
                    }
        }
      

  3.   


    不要针对这段HTML,谁知道别的表单name属性是什么?我要能“遍历表单元素”的程序!
      

  4.   


    那就webClient GET HTML下来,检索<form></form>的位置
      

  5.   

    string type="",s="";
                HtmlDocument htm = this.webBrowser1.Document;
                HtmlElementCollection all = htm.All;
                for (int i = 0; i < all.Count; i++)
                {
                    HtmlElement elem = all[i];
                    if (elem.TagName.ToLower() == type)
                    {
                       s=elem.GetAttribute("name").ToString();
                    }
                 } 
    HtmlElementCollection htmlTabs = webBrowser1.Document.GetElementsByTagName("table");
                if(htmlTabs!=null&&htmlTabs.length>0)
                {
                    HtmlElement htmlTable = htmlElements[0];
                    HtmlElementCollection htmlRows = htmlElement.GetElementsByTagName("tr");
                    HtmlElementCollection htmlCells = null;
                    foreach (HtmlElement htmlRow in htmlRows)
                    {
                            htmlCells = htmlRow.GetElementsByTagName("td");                 
                            foreach (HtmlElement htmlCell in htmlCells)
                            {
                                if (htmlCell.InnerText!=null)
                                {
                                    strValue = htmlCell.InnerText.Trim();                
                                                         
                                }                        
                            }
                    }
                }
    递归遍历
      

  6.   

    完全是瞎扯,要需要用正则,我干嘛还要整DOM.
      

  7.   

    HtmlDocument doc = webBrowser1.Document;
                HtmlElementCollection forms= doc.Forms;
    foreach (HtmlElement form in forms)
    {
                foreach (HtmlElement element in form.All)
                {
                    if (element.GetAttribute("type") == "hidden")
                    {
                        Console.WriteLine(element.GetAttribute("name"));
                        Console.WriteLine(element.GetAttribute("value"));
                    }
                }
    }
      

  8.   

    strValue?哪儿来的, htmlElements哪来的?
      

  9.   


     HtmlElementCollection elements = myWebBrowser.Document.All;
                foreach (HtmlElement element in elements)
                {
                    if ("hidden" == element.GetAttribute("type"))
                    {
                        string str = "name=" + element.GetAttribute("name")
                        + " value=" + element.GetAttribute("value");                    listBox1.Items.Add(str);
                    }
                }
    这段代码有什么问题?
      

  10.   

    foreach(HtmlElement element in form.All)
    {
    }