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 应用程 ...
随机推荐
- 大数据学习——下载集群根目录下的文件到E盘
代码如下: package cn.itcast.hdfs; import java.io.IOException; import org.apache.hadoop.conf.Configuratio ...
- XV6上下文切换
上下文切换分为两种情况 用户程序陷入到内核,再从内核返回 两个应用程序之间的上下文切换 用户程序陷入到内核 用户程序陷入到内核通过中断INT指令,在xv6中系统调用的号为64 操作系统在初始化的时候会 ...
- react.js 给标识ref,获取内容
import React,{Component} from 'react' import ReactDOM from 'react-dom' class App extends Component{ ...
- HDU 4651 (生成函数)
HDU 4651 Partition Problem : n的整数划分方案数.(n <= 100008) Solution : 参考资料: 五角数 欧拉函数 五边形数定理 整数划分 一份详细的题 ...
- linux命令2——进程相关
(1)ps -ef :可以看到内核的线程.
- MongoDB学习day09--Mongoose aggregate 多表关联查询
Mongodb的aggregate应用之前已经说过了. 可以参考day06 Mongoose的aggregate函数应用 var mongoose=require('./db.js'); var Or ...
- css实现文字渐变
css文件渐变虽然兼容性比较差,但是用在移动端和chrome中还是没有问题的. 实现文件渐变的方法有两种 1. 使用 background 的属性 2. 使用 mask 属性 方式一. <!DO ...
- json解析bug之ERROR ExceptionController:185 - not close json text, token : :
错误:ERROR ExceptionController:185 - not close json text, token : : 原因:json数据格式有误.!我的错误是,缺少了一个包括json数据 ...
- 【c++】面向对象程序设计之继承中的类作用域
当存在继承关系时,派生类的作用域嵌套在其基类的作用域之内. 一个对象.引用或指针的静态类型决定了该对象的哪些成员是可见的.即使静态类型与动态类型可能不一致,但我们使用哪些成员仍然是由静态类型决定的.基 ...
- Android之怎样实现滑动页面切换【Fragment】
Fragment 页面切换不能滑动 所以对于listview 能够加入的左右滑动事件 .不会有冲突比如(QQ的好友列表的删除) Fragment 和viewpager 的差别 Viewpager ...