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 应用程 ...
随机推荐
- 将树莓派3B+变成WiFi热点
我有一个树莓派3B+,安装的是官方的Raspbian Stretch操作系统,该系统和Debian 9很类似,很多命令都是通用的. 接下来我将演示如何利用树莓派搭建WiFi热点,此热点就和家里的无线路 ...
- 简单的MVC 权限管理
花了3天时间研究了下对于 NHibernate+MVC4+bootstrap+Redis(这个是选配只做了登陆测试)+T4 这些都是第一次使用.用着有些生硬权当鼓励下自己,记录下来有空就继续完善. 思 ...
- HDU 4597
题目大意: 两人轮流从两堆牌从抽取最顶端或者最底部的牌,得到的分数加到自己身上,问先拿牌的最多能得多少分 记忆化搜索,2堆牌的底和顶,有四种方法,根据四种方法来找到最优解 #include <c ...
- HDU1711 最基础的kmp算法
Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], .... ...
- 公路修建(Prim)
洛谷传送门 这道水题告诉了我,堆优化的prim有时还不如朴素prim快... 居然记错时间复杂度了,我也真是菜. #include <cstdio> #include <queue& ...
- 内存管理——(exceptional C++ 条款9,条款10)
C++的各个内存区域: (1)常量数据(const data)区 常量数据区存储的是字符串等在编译期间就能确定的值,在整个程序的生命周期内,这里的数据都是可用.区域内所有的数据都是 只读的. (2)栈 ...
- msp430项目编程21
msp430中项目---直流电机控制系统 1.定时器工作原理 2.电路原理说明 3.代码(显示部分) 4.代码(功能实现) 5.项目总结 msp430项目编程 msp430入门学习
- QueenAttack
问题分析: 1.对于行和列,要求得每行或每列的棋子个数,只需要把横坐标或纵坐标相同的棋子数目相加即可,然后使用k*(k-1)/2就可求得攻击次数 2.对于对角线上的点,需要分析对角线上点的坐标关系.分 ...
- PB编译
java -jar wire-compiler-1.8.0-jar-with-dependencies.jar --java_out=./ ngame.proto 其中java_out是指输出要放在 ...
- 通过继承Thread类来创建多线程 关键词 start
// 代码 public class MyThread extends Thread { public void run(){ for(int i=0;i<10;i++){ try { Thre ...