C#使用 webBrowser 控件总结
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.IO; namespace WindowsFormsApplication1
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent(); }
void mouse_OnMouseActivity(object sender, MouseEventArgs e)
{
string str = "X:" + e.X + " Y:" + e.Y;
this.Text = str;
}
#region API单击
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
private void DoMouseClick(int ex, int ey)
{
IntPtr handle = this.webBrowser1.Handle;
StringBuilder lpClassName = new StringBuilder();
while (lpClassName.ToString() != "Internet Explorer_Server")
{
handle = GetWindow(handle, );
GetClassName(handle, lpClassName, lpClassName.Capacity);
}
IntPtr lParam = (IntPtr)((ey << 0x10) | ex);
IntPtr zero = IntPtr.Zero;
SendMessage(handle, 0x201, zero, lParam);
SendMessage(handle, 0x202, zero, lParam);
}
private void DoMouseClick(IntPtr handle, int ex, int ey)
{
StringBuilder lpClassName = new StringBuilder();
while (lpClassName.ToString() != "Internet Explorer_Server")
{
handle = GetWindow(handle, );
GetClassName(handle, lpClassName, lpClassName.Capacity);
}
IntPtr lParam = (IntPtr)((ey << 0x10) | ex);
IntPtr zero = IntPtr.Zero;
SendMessage(handle, 0x201, zero, lParam);
SendMessage(handle, 0x202, zero, lParam);
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
#endregion int i = ;
private void Form4_Load(object sender, EventArgs e)
{
txt_uid.Text = listBox1.Items[].ToString().Replace("----", "-").Split('-')[];
txt_pwd.Text = listBox1.Items[].ToString().Replace("----", "-").Split('-')[];
//timer1.Interval = 20;
//timer1.Interval = 1000;
//timer1.Interval = 2000;
}
MouseHook mouse = new MouseHook();
private void button1_Click(object sender, EventArgs e)
{ try
{
// i++;
//if (i > listBox1.Items.Count)
//{
// MessageBox.Show("全部已打开一次");
// return;
//}
//txt_uid.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[0];
//txt_pwd.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[1]; HtmlDocument cd = webBrowser1.Document;
HtmlElement element = webBrowser1.Document.GetElementById("uin");//id或者是name
element.InnerText = txt_uid.Text;
element = webBrowser1.Document.GetElementById("pwd");//id或者是name
element.InnerText = txt_pwd.Text; // 第一种情况butten 按钮有id或者name
HtmlElement buttonSubmit = this.webBrowser1.Document.GetElementById("submitBtn");
buttonSubmit.InvokeMember("click");
}
catch (Exception)
{ // throw;
} } private void button2_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(new Uri("https://w.mail.qq.com/cgi-bin/loginpage?f=xhtml"));
} private void button3_Click(object sender, EventArgs e)
{
Rectangle rt = webBrowser1.Document.Body.ScrollRectangle;
webBrowser1.Document.Window.ScrollTo(, rt.Height);
} private void button5_Click(object sender, EventArgs e)
{
i++;
if (i > listBox1.Items.Count)
return;
txt_uid.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[];
txt_pwd.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[];
} private void button6_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
Read("1.txt");
labcout.Text = "总共:"+listBox1.Items.Count.ToString();
i = ;
}
public void Read(string path)
{
StreamReader sr = new StreamReader(path, Encoding.Default);
String line;
while ((line = sr.ReadLine()) != null)
{
listBox1.Items.Add(line.ToString());
}
} private void button7_Click(object sender, EventArgs e)
{
//HtmlElementCollection link = this.webBrowser1.Document.GetElementsByTagName("a");
// for (int ii = 0; ii < link.Count; ii++)
// {
// if (link[ii].GetAttribute("href").ToLower().IndexOf("http://mail.qq.com/cgi-bin/frame_html?") == 0 && link[ii].GetAttribute("href").ToLower().IndexOf("&st=0&p=") > 0) // link[ii].InvokeMember("click");
// }
herfclick("http://mail.qq.com/cgi-bin/frame_html?f=html&sid=rxOuQ-CEBfe1KCx4Uc-T5vNw");
// http://mail.qq.com/cgi-bin/frame_html?f=html&sid=9YMxbM2xOc2PCHMnUfnT5vNw
}
private void herfclick(string url)
{ for (int i = ; i < webBrowser1.Document.All.Count; i++)
{
if (webBrowser1.Document.All[i].GetAttribute("href").ToString().Trim().Length > )
{
if (webBrowser1.Document.All[i].TagName == "A" && webBrowser1.Document.All[i].GetAttribute("href").ToString().Trim().Substring(, ) == url.Substring(, ))
{ webBrowser1.Document.All[i].InvokeMember("click");//引发”CLICK”事件 break; }
}
} } private void listBox1_Click(object sender, EventArgs e)
{
txt_uid.Text =listBox1.Items[listBox1.SelectedIndex].ToString().Replace("----", "-").Split('-')[];
txt_pwd.Text = listBox1.Items[listBox1.SelectedIndex].ToString().Replace("----", "-").Split('-')[];
timer1.Start();
timer2.Start();
timer3.Start();
timer4.Start();
} private void button8_Click(object sender, EventArgs e)
{
//
webBrowser1.Navigate(new Uri("https://w.mail.qq.com/cgi-bin/loginpage?f=xhtml"));
Thread.Sleep();
Rectangle rt = webBrowser1.Document.Body.ScrollRectangle;
webBrowser1.Document.Window.ScrollTo(, rt.Height);
//
try
{
// i++;
//if (i > listBox1.Items.Count)
//{
// MessageBox.Show("全部已打开一次");
// return;
//}
//txt_uid.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[0];
//txt_pwd.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[1]; HtmlDocument cd = webBrowser1.Document;
HtmlElement element = webBrowser1.Document.GetElementById("uin");//id或者是name
element.InnerText = txt_uid.Text;
element = webBrowser1.Document.GetElementById("pwd");//id或者是name
element.InnerText = txt_pwd.Text; // 第一种情况butten 按钮有id或者name
HtmlElement buttonSubmit = this.webBrowser1.Document.GetElementById("submitBtn");
buttonSubmit.InvokeMember("click");
}
catch (Exception)
{ // throw;
}
//
herfclick("http://mail.qq.com/cgi-bin/frame_html?f=html&sid=rxOuQ-CEBfe1KCx4Uc-T5vNw");
} private void timer1_Tick(object sender, EventArgs e)
{
webBrowser1.Navigate(new Uri("https://w.mail.qq.com/cgi-bin/loginpage?f=xhtml"));
timer1.Stop();
} private void timer2_Tick(object sender, EventArgs e)
{
try
{
// i++;
//if (i > listBox1.Items.Count)
//{
// MessageBox.Show("全部已打开一次");
// return;
//}
//txt_uid.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[0];
//txt_pwd.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[1]; HtmlDocument cd = webBrowser1.Document;
HtmlElement element = webBrowser1.Document.GetElementById("uin");//id或者是name
element.InnerText = txt_uid.Text;
element = webBrowser1.Document.GetElementById("pwd");//id或者是name
element.InnerText = txt_pwd.Text; // 第一种情况butten 按钮有id或者name
HtmlElement buttonSubmit = this.webBrowser1.Document.GetElementById("submitBtn");
buttonSubmit.InvokeMember("click");
}
catch (Exception)
{ // throw;
}
timer2.Stop();
} private void timer3_Tick(object sender, EventArgs e)
{
//模拟点击某个链接
herfclick("http://mail.qq.com/cgi-bin/frame_html?f=html&sid=rxOuQ-CEBfe1KCx4Uc-T5vNw");
timer3.Stop();
} private void button9_Click(object sender, EventArgs e)
{
timer1.Start();
timer2.Start();
timer3.Start(); } private void timer4_Tick(object sender, EventArgs e)
{
//模拟点击某个链接
herfclick("http://mail.qq.com/cgi-bin/frame_html?f=html&sid=rxOuQ-CEBfe1KCx4Uc-T5vNw");
// timer4.Stop();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.IO; namespace WindowsFormsApplication1
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent(); }
void mouse_OnMouseActivity(object sender, MouseEventArgs e)
{
string str = "X:" + e.X + " Y:" + e.Y;
this.Text = str;
}
#region API单击
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
private void DoMouseClick(int ex, int ey)
{
IntPtr handle = this.webBrowser1.Handle;
StringBuilder lpClassName = new StringBuilder();
while (lpClassName.ToString() != "Internet Explorer_Server")
{
handle = GetWindow(handle, );
GetClassName(handle, lpClassName, lpClassName.Capacity);
}
IntPtr lParam = (IntPtr)((ey << 0x10) | ex);
IntPtr zero = IntPtr.Zero;
SendMessage(handle, 0x201, zero, lParam);
SendMessage(handle, 0x202, zero, lParam);
}
private void DoMouseClick(IntPtr handle, int ex, int ey)
{
StringBuilder lpClassName = new StringBuilder();
while (lpClassName.ToString() != "Internet Explorer_Server")
{
handle = GetWindow(handle, );
GetClassName(handle, lpClassName, lpClassName.Capacity);
}
IntPtr lParam = (IntPtr)((ey << 0x10) | ex);
IntPtr zero = IntPtr.Zero;
SendMessage(handle, 0x201, zero, lParam);
SendMessage(handle, 0x202, zero, lParam);
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
#endregion int i = ;
private void Form4_Load(object sender, EventArgs e)
{
txt_uid.Text = listBox1.Items[].ToString().Replace("----", "-").Split('-')[];
txt_pwd.Text = listBox1.Items[].ToString().Replace("----", "-").Split('-')[];
//timer1.Interval = 20;
//timer1.Interval = 1000;
//timer1.Interval = 2000;
}
MouseHook mouse = new MouseHook();
private void button1_Click(object sender, EventArgs e)
{ try
{
// i++;
//if (i > listBox1.Items.Count)
//{
// MessageBox.Show("全部已打开一次");
// return;
//}
//txt_uid.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[0];
//txt_pwd.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[1]; HtmlDocument cd = webBrowser1.Document;
HtmlElement element = webBrowser1.Document.GetElementById("uin");//id或者是name
element.InnerText = txt_uid.Text;
element = webBrowser1.Document.GetElementById("pwd");//id或者是name
element.InnerText = txt_pwd.Text; // 第一种情况butten 按钮有id或者name
HtmlElement buttonSubmit = this.webBrowser1.Document.GetElementById("submitBtn");
buttonSubmit.InvokeMember("click");
}
catch (Exception)
{ // throw;
} } private void button2_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(new Uri("https://w.mail.qq.com/cgi-bin/loginpage?f=xhtml"));
} private void button3_Click(object sender, EventArgs e)
{
Rectangle rt = webBrowser1.Document.Body.ScrollRectangle;
webBrowser1.Document.Window.ScrollTo(, rt.Height);
} private void button5_Click(object sender, EventArgs e)
{
i++;
if (i > listBox1.Items.Count)
return;
txt_uid.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[];
txt_pwd.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[];
} private void button6_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
Read("1.txt");
labcout.Text = "总共:"+listBox1.Items.Count.ToString();
i = ;
}
public void Read(string path)
{
StreamReader sr = new StreamReader(path, Encoding.Default);
String line;
while ((line = sr.ReadLine()) != null)
{
listBox1.Items.Add(line.ToString());
}
} private void button7_Click(object sender, EventArgs e)
{
//HtmlElementCollection link = this.webBrowser1.Document.GetElementsByTagName("a");
// for (int ii = 0; ii < link.Count; ii++)
// {
// if (link[ii].GetAttribute("href").ToLower().IndexOf("http://mail.qq.com/cgi-bin/frame_html?") == 0 && link[ii].GetAttribute("href").ToLower().IndexOf("&st=0&p=") > 0) // link[ii].InvokeMember("click");
// }
herfclick("http://mail.qq.com/cgi-bin/frame_html?f=html&sid=rxOuQ-CEBfe1KCx4Uc-T5vNw");
// http://mail.qq.com/cgi-bin/frame_html?f=html&sid=9YMxbM2xOc2PCHMnUfnT5vNw
}
private void herfclick(string url)
{ for (int i = ; i < webBrowser1.Document.All.Count; i++)
{
if (webBrowser1.Document.All[i].GetAttribute("href").ToString().Trim().Length > )
{
if (webBrowser1.Document.All[i].TagName == "A" && webBrowser1.Document.All[i].GetAttribute("href").ToString().Trim().Substring(, ) == url.Substring(, ))
{ webBrowser1.Document.All[i].InvokeMember("click");//引发”CLICK”事件 break; }
}
} } private void listBox1_Click(object sender, EventArgs e)
{
txt_uid.Text =listBox1.Items[listBox1.SelectedIndex].ToString().Replace("----", "-").Split('-')[];
txt_pwd.Text = listBox1.Items[listBox1.SelectedIndex].ToString().Replace("----", "-").Split('-')[];
timer1.Start();
timer2.Start();
timer3.Start();
timer4.Start();
} private void button8_Click(object sender, EventArgs e)
{
//
webBrowser1.Navigate(new Uri("https://w.mail.qq.com/cgi-bin/loginpage?f=xhtml"));
Thread.Sleep();
Rectangle rt = webBrowser1.Document.Body.ScrollRectangle;
webBrowser1.Document.Window.ScrollTo(, rt.Height);
//
try
{
// i++;
//if (i > listBox1.Items.Count)
//{
// MessageBox.Show("全部已打开一次");
// return;
//}
//txt_uid.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[0];
//txt_pwd.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[1]; HtmlDocument cd = webBrowser1.Document;
HtmlElement element = webBrowser1.Document.GetElementById("uin");//id或者是name
element.InnerText = txt_uid.Text;
element = webBrowser1.Document.GetElementById("pwd");//id或者是name
element.InnerText = txt_pwd.Text; // 第一种情况butten 按钮有id或者name
HtmlElement buttonSubmit = this.webBrowser1.Document.GetElementById("submitBtn");
buttonSubmit.InvokeMember("click");
}
catch (Exception)
{ // throw;
}
//
herfclick("http://mail.qq.com/cgi-bin/frame_html?f=html&sid=rxOuQ-CEBfe1KCx4Uc-T5vNw");
} private void timer1_Tick(object sender, EventArgs e)
{
webBrowser1.Navigate(new Uri("https://w.mail.qq.com/cgi-bin/loginpage?f=xhtml"));
timer1.Stop();
} private void timer2_Tick(object sender, EventArgs e)
{
try
{
// i++;
//if (i > listBox1.Items.Count)
//{
// MessageBox.Show("全部已打开一次");
// return;
//}
//txt_uid.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[0];
//txt_pwd.Text = listBox1.Items[i].ToString().Replace("----", "-").Split('-')[1]; HtmlDocument cd = webBrowser1.Document;
HtmlElement element = webBrowser1.Document.GetElementById("uin");//id或者是name
element.InnerText = txt_uid.Text;
element = webBrowser1.Document.GetElementById("pwd");//id或者是name
element.InnerText = txt_pwd.Text; // 第一种情况butten 按钮有id或者name
HtmlElement buttonSubmit = this.webBrowser1.Document.GetElementById("submitBtn");
buttonSubmit.InvokeMember("click");
}
catch (Exception)
{ // throw;
}
timer2.Stop();
} private void timer3_Tick(object sender, EventArgs e)
{
//模拟点击某个链接
herfclick("http://mail.qq.com/cgi-bin/frame_html?f=html&sid=rxOuQ-CEBfe1KCx4Uc-T5vNw");
timer3.Stop();
} private void button9_Click(object sender, EventArgs e)
{
timer1.Start();
timer2.Start();
timer3.Start(); } private void timer4_Tick(object sender, EventArgs e)
{
//模拟点击某个链接
herfclick("http://mail.qq.com/cgi-bin/frame_html?f=html&sid=rxOuQ-CEBfe1KCx4Uc-T5vNw");
// timer4.Stop();
}
}
}
C#使用 webBrowser 控件总结的更多相关文章
- C#中的WebBrowser控件的使用
0.常用方法 Navigate(string urlString):浏览urlString表示的网址 Navigate(System.Uri url):浏览url表示的网址 Navigate(st ...
- delphi WebBrowser控件上网页验证码图片识别教程(一)
步骤一:获取网页中验证码图片的url地址 在delphi中加入一个BitBtn和一个memo以及WebBrowser控件实现网页中验证码图片的url地址的获取 程序如下:procedure TForm ...
- <总结>delphi WebBrowser控件的使用中出现的bug
Delphi WebBrowser控件的使用中出现的bug: 1.WebBrowser.Visible=false:Visible属性不能使WebBrowser控件不可见,暂时用 WebBrowse ...
- C# WebBrowser控件使用教程与技巧收集
常用的方法 Navigate(string urlString):浏览urlString表示的网址 Navigate(System.Uri url):浏览url表示的网址 Navigate(strin ...
- C# 指定Webbrowser控件所用IE内核版本
如果电脑上安装了IE8或者之后版本的IE浏览器,Webbrowser控件会使用IE7兼容模式来显示网页内容.解决方法是在注册表中为你的进程指定引用IE的版本号. 比如我的程序叫做a.exe,以64位机 ...
- 在WPF的WebBrowser控件中屏蔽脚本错误的提示
在WPF中使用WebBrowser控件显示网页时,经常会报脚本错误的提示,如何屏蔽掉这些错误提示呢.方法是定义如下方法: public void SuppressScriptErrors(WebBro ...
- 修改WebBrowser控件的内核解决方案
方法一 加入你想让WebBrowser控件的渲染模式编程IE8的标准模式, 你可以通过设置注册表FEATURE_BROWSER_EMULATION 来实现. 示例: 注册表中注明当前本机装的IE版本H ...
- C# webBrowser控件使用
C# webBrowser控件使用心得 最近用到WebBrowser控件,遇到很多问题,也学习了不少新的东西.下面是我在C#下写的关于WebBrowser控件使用的代码. 1.WebBrowser常用 ...
- WebBrowser控件打开https站点
背景: 与上一篇博文一样,此文亦是由于开发DropboxAPI中遇到问题衍生出来的.由于需要重定向https类型网站,但自己的https证书是自签名的,总是提示'网站的安全证书存在问题'. 鉴此,查了 ...
- C++(MFC)中WebBrowser去除3D边框的方法(实现IDocHostUIHandler接口)控制 WebBrowser 控件的外观和行为
在 CSDN 上经常看到以下两个问题:1.在 MFC 应用程序中,如果创建了一个 WebBrowser 控件(包括 CHtmlView 在内),如何可以把该控件的三维边框禁止掉?2.在 MFC 应用程 ...
随机推荐
- 如何安装python包
安装python包有两种方法: 使用Python包管理器pip工具 在Linux系统中,首先 yum install python-pip 然后就可以欢快的pip install *** 啦 源代码安 ...
- .net对象的生命周期
阅读了文章:.NET对象生命周期小结 文章分多个部分,第一部分:介绍了,创建对象时,内存的分配,对象真正被创建,以及经历各阶段垃圾回收的过程. 第二部分,介绍了Finalize与Dispsose方法.
- hdu1856 选出更多的孩子
题目大意: 老师选取2个学生对应的号码,这两人视作朋友,同时朋友的朋友也可以看成自己的朋友. 最后老师选出一个人数最多的朋友圈. 这里学生的人数不大于10^7,所以操作时需要极为注意,操作步数能省则省 ...
- visual studio用"查找替换"来删掉源代码中所有//方式的纯注释和空行
visual studio用"查找替换"来删掉源代码中所有//方式的纯注释和空行 注意:包括/// <summary>这样的XML注释也都删掉了. 步骤1/2(删除注释 ...
- 潘多拉的盒子(bzoj 1194)
Description Input 第一行是一个正整数S,表示宝盒上咒语机的个数,(1≤S≤50).文件以下分为S块,每一块描述一个咒语机,按照咒语机0,咒语机1„„咒语机S-1的顺序描述.每一块的格 ...
- Wannafly挑战赛2_D Delete(拓扑序+最短路+线段树)
Wannafly挑战赛2_D Delete Problem : 给定一张n个点,m条边的带权有向无环图,同时给定起点S和终点T,一共有q个询问,每次询问删掉某个点和所有与它相连的边之后S到T的最短路, ...
- apache cgi 模块安装
apache安装,请参照:http://httpd.apache.org/docs/2.4/ 安装系统: Fedora release 21 (Twenty One) (x64) 版本:Server ...
- msp430项目编程10
msp430中项目---电子密码锁 1.扫描键盘工作原理 2.电路原理说明 3.代码(显示部分) 4.代码(功能实现) 5.项目总结 msp430项目编程 msp430入门学习
- python学习之 - configparser模块
configparser模块功能:用于生成和修改常见配置文件.基本常用方法如下: read(filename):直接读取配置文件write(filename):将修改后的配置文件写入文件中.defau ...
- Codeforces 549C(博弈)
C. The Game Of Parity time limit per test 1 second memory limit per test 256 megabytes input standar ...