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 应用程 ...
随机推荐
- 【C#】【数据结构】006-栈:链栈
C#数据结构:链栈 1.自定义链栈结构: 链栈节点类 using System.Collections; using System.Collections.Generic; using UnityEn ...
- ArrayList练习之存储字符串并遍历
在myArrayList项目下 新建一个包 在这个包中新建一个类:ArrayListDemo4.java ArrayListDemo4.java import java.util.ArrayList; ...
- python接口自动化-multipart/form-data上传图片
前言 在提交表单操作的时候,经常会遇到图片上传的操作,图片上传是一个单独的接口,本篇以禅道为例,介绍如何上传图片 上传接口 1.以禅道上提交bug为例,在选择图片时,点确定按钮,就是上传图片了 2.用 ...
- 大数据学习——sqoop入门
下载地址 https://pan.baidu.com/s/1qWDl29L9I_KVU54c0ioNfQ fvfh 3.1 概述 sqoop是apache旗下一款“Hadoop和关系数据库服务器之间传 ...
- Python 单向队列Queue模块详解
Python 单向队列Queue模块详解 单向队列Queue,先进先出 '''A multi-producer, multi-consumer queue.''' try: import thread ...
- Codeforces 892 A.Greed
A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- VS Code 列编辑功能说明
新版本v1.13.1或者附近的版本中的列编辑功能已经调整. 一.多光标插入功能 Alt+鼠标左键,添加多光标输入 二.自由多行选择 Alt键+鼠标左键拖动选择各行的部分内容 三.列选择 Shift+A ...
- 获得HttpServletRequest 和HttpSession对象
package org.jeecgframework.core.util; import java.util.HashMap; import java.util.Map; import javax.s ...
- 神秘数(bzoj 4408)
Description 一个可重复数字集合S的神秘数定义为最小的不能被S的子集的和表示的正整数.例如S={1,1,1,4,13}, 1 = 1 2 = 1+1 3 = 1+1+1 4 = 4 5 = ...
- WebService流行框架CXF
CXF官方网址:http://cxf.apache.org/ CXF官方网址:官网学习地址:http://cxf.apache.org/docs/index.html 官网下载cxf压缩文件: ...