c# 控制IE浏览器
来源:互联网 发布:一般淘宝客服休息时间 编辑:程序博客网 时间:2024/05/21 09:23
想写一个桌面程序,用C#。
程序运行后,会用IE打开指定的网页,并自动登录网站,再根据需要进行一些操作。
关键是不知道怎么控制IE浏览器,请大家指点一下。
相关内容如下:
C#控制IE浏览器
引入 C:\WINDOWS\System32\mshtml.tlb、Interop.SHDocVw.dll
/// <summary>
/// 返回指定Url的IE窗口下的 IHTMLDocument2 对象。
/// </summary>
/// <returns>IHTMLDocument2</returns>
public static IHTMLDocument2 GetIHTMLDocument2ByUrl(string url)
{
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
string filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals(“iexplore“) && ie.LocationURL == url)
{
return ie.Document as IHTMLDocument2;
}
}
}
通过 GetIHTMLDocument2ByUrl 方法可以获取已打开的IE窗口中指写地址的窗口中的 IHTMLDocument2 对象。
利用这个对象,就可以进行相关操作。
1.填写表单
IHTMLDocument2 iHTMLDocument2 = GetIHTMLDocument2ByUrl(“http://www.163.com“);
IHTMLInputElement input = (IHTMLInputElement)iHTMLDocument2.all.item(“Username“, 0); // 获取指定名称的对象
input.value = “Xiao“; // 赋值
2.点击按钮
IHTMLDocument2 iHTMLDocument2 = GetIHTMLDocument2ByUrl(“http://www.163.com“);
HTMLDocumentClass obj = (HTMLDocumentClass)iHTMLDocument2;
IHTMLElement iHTMLElement = null;
IHTMLElementCollection c = obj.getElementsByTagName(“input“);
foreach (IHTMLElement e in c)
{
if (e.outerHTML.IndexOf(“登录“) != -1)
{
iHTMLElement = e;
break;
}
}
if (iHTMLElement != null)
{
iHTMLElement.click(); // 点击登录按钮
}
程序运行后,会用IE打开指定的网页,并自动登录网站,再根据需要进行一些操作。
关键是不知道怎么控制IE浏览器,请大家指点一下。
相关内容如下:
C#控制IE浏览器
引入 C:\WINDOWS\System32\mshtml.tlb、Interop.SHDocVw.dll
/// <summary>
/// 返回指定Url的IE窗口下的 IHTMLDocument2 对象。
/// </summary>
/// <returns>IHTMLDocument2</returns>
public static IHTMLDocument2 GetIHTMLDocument2ByUrl(string url)
{
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
string filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals(“iexplore“) && ie.LocationURL == url)
{
return ie.Document as IHTMLDocument2;
}
}
}
通过 GetIHTMLDocument2ByUrl 方法可以获取已打开的IE窗口中指写地址的窗口中的 IHTMLDocument2 对象。
利用这个对象,就可以进行相关操作。
1.填写表单
IHTMLDocument2 iHTMLDocument2 = GetIHTMLDocument2ByUrl(“http://www.163.com“);
IHTMLInputElement input = (IHTMLInputElement)iHTMLDocument2.all.item(“Username“, 0); // 获取指定名称的对象
input.value = “Xiao“; // 赋值
2.点击按钮
IHTMLDocument2 iHTMLDocument2 = GetIHTMLDocument2ByUrl(“http://www.163.com“);
HTMLDocumentClass obj = (HTMLDocumentClass)iHTMLDocument2;
IHTMLElement iHTMLElement = null;
IHTMLElementCollection c = obj.getElementsByTagName(“input“);
foreach (IHTMLElement e in c)
{
if (e.outerHTML.IndexOf(“登录“) != -1)
{
iHTMLElement = e;
break;
}
}
if (iHTMLElement != null)
{
iHTMLElement.click(); // 点击登录按钮
}
- c# 控制IE浏览器
- c# 控制IE浏览器
- C#控制IE浏览器
- c++控制ie浏览器
- C#操作IE浏览器
- c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2
- c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2
- c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2
- c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2
- C# 设置IE浏览器代理
- C# 获取IE浏览器句柄
- IE浏览器兼容问题,CSS控制bug
- C# 获取IE浏览器的HTML内容
- 用Visual C#打造个性化的IE浏览器IE
- VB完全控制IE浏览器,操作ie对象,响应ie事件
- WebBrowser控件实现对IE浏览器的各种控制
- 用Delphi编程控制IE浏览器的窗口
- 防止黑客用IE浏览器实现远程控制
- (LA 3708)墓地雕塑(Graveyard )
- Linux用init命令关机、重启、切换模式
- 【Copy】HTTPS连接的前几毫秒发生了什么
- while 語句(1) for C
- 2013 ACM/ICPC Asia Regional Changsha Online - E Travel by Bike
- c# 控制IE浏览器
- leetcode_question_101 Symmetric Tree
- HTTP协议详解
- java中的一些注意事项
- Why all bytes are zero for code?
- irrlicht bsp浏览器
- shell中read参数
- 字符串处理算法(一)检测输入字符串中是否包含连续的或者离散的test
- MyEclipse6.0安装SVN