惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
人人都是产品经理
人人都是产品经理
博客园 - 【当耐特】
量子位
有赞技术团队
有赞技术团队
博客园 - 三生石上(FineUI控件)
博客园 - Franky
M
MIT News - Artificial intelligence
U
Unit 42
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
The Cloudflare Blog
J
Java Code Geeks
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
MyScale Blog
MyScale Blog
T
Tailwind CSS Blog
T
The Blog of Author Tim Ferriss
V
V2EX

博客园 - Mat

VBScript Functions and Keyword - Mat Windows Management Interface (WMI) 用div布局时怎么让文字或图片垂直居中对齐呢? CSS控制的内容超过容器宽度后显示省略号 div内容可编辑 Access C#从视频截图的方法 异步工作流体系结构的选择 笔记 CSS 布局 如何在 ASP.NET 应用程序中实现模拟 再谈css--如何针对不同位置的元素使用不同的风格 给web用户控件自定义后台事件 Hashtable Dictionary 《冰鉴》—— 《金刚经》 《道子》——大智慧 排序算法 .Net C# 集合
vs2005中的WebBrowser控件的简单应用
Mat · 2006-11-27 · via 博客园 - Mat

看看这段代码,可以用来分析网页上的元素的类型的。

        private void btn_Find_Click(object sender, EventArgs e)
        
{
            
//find all the input controls on the page
            if (this.wb_Show.Document == null)
            

                MessageBox.Show(
"请先打开一个要分析的网页");
                
return;            
            }

            
string type = this.cbx_type.Text.ToLower().Trim();
            
if (type == "")
            
{
                MessageBox.Show(
"请选择一个分析对象的类型");
                
return;
            }

            
this.lb_InputList.Items.Clear();
            HtmlDocument htm 
= this.wb_Show.Document;
            HtmlElementCollection all 
= htm.All;
            
for (int i = 0; i < all.Count; i++)
            
{
                HtmlElement elem 
= all[i];
                
if (elem.TagName.ToLower() == type)
                
{
                    
this.lb_InputList.Items.Add(elem.Name);
                }

            }

            MessageBox.Show(
"总共找到" + this.lb_InputList.Items.Count.ToString() + "个符合条件的结果");
        }

这一段代码是用来触发按钮事件的,注意使用的是click参数

                     if (elem.Name.ToLower() == login.Attributes["name"].Value)
                     
{
                         
//elem.InvokeMember("click");
                         elem.InvokeMember("click");

                     }

对于form的提交,得使用submit


             
else
             
{
                 XmlNode form 
= FindNode("form");
                 htm.Forms[form.Attributes[
"name"].Value].InvokeMember("submit");
             }

获取值,和赋值类似

                XmlNode userName = FindNode("userName");
                
if (elem.TagName.ToLower() == "input" && elem.Name.ToLower() == userName.Attributes["name"].Value)
                
{
                    elem.InnerText 
= userName.InnerText;
                }