vs2005中的WebBrowser控件的简单应用
看看这段代码,可以用来分析网页上的元素的类型的。
这一段代码是用来触发按钮事件的,注意使用的是click参数
对于form的提交,得使用submit
else
{
XmlNode form = FindNode("form");
htm.Forms[form.Attributes["name"].Value].InvokeMember("submit");
}
获取值,和赋值类似
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() + "个符合条件的结果");
}
{
//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");
}
{
//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;
}
if (elem.TagName.ToLower() == "input" && elem.Name.ToLower() == userName.Attributes["name"].Value)
{
elem.InnerText = userName.InnerText;
}