惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Forbes - Security
Forbes - Security
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
W
WeLiveSecurity
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
Engineering at Meta
Engineering at Meta
PCI Perspectives
PCI Perspectives
Martin Fowler
Martin Fowler
T
The Exploit Database - CXSecurity.com
F
Full Disclosure
WordPress大学
WordPress大学
S
Security Affairs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
SegmentFault 最新的问题
P
Privacy International News Feed
IT之家
IT之家
M
MIT News - Artificial intelligence
G
GRAHAM CLULEY
Hacker News: Ask HN
Hacker News: Ask HN
D
DataBreaches.Net
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Check Point Blog
美团技术团队
Security Latest
Security Latest
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
H
Help Net Security
宝玉的分享
宝玉的分享
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
The Cloudflare Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
爱范儿
爱范儿
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
I
InfoQ
N
News | PayPal Newsroom
TaoSecurity Blog
TaoSecurity Blog

博客园 - Ring

运行Java cmd程序 找不到或无法加载主类怎么解决 Generics and Collection (2) Generics and Collection (1) mybatis, spring, springmvc 什么时候该用NoSQL? 如何学习Javascript 好文章尽收眼底 事务和锁 索引 VS调试Javascript. Asp.net常用状态管理方案分析 .NET中的缓存知识总结 "The server has rejected the client credentials"解决方案 - Ring 有关IIS7概述以及配置和开发的几篇文章摘录 是什么使得我的进程崩溃了? OutOfMemory这家伙是谁?为什么我还留有许多内存,它却使进程崩溃了? ASP.NET 崩溃-SiteMap中疯狂的循环 何时.NET中AppDomain会回收? .NET如何使用内存---餐馆案例分析
CodeForFun--编写自动登录Email的程序
Ring · 2006-11-09 · via 博客园 - Ring

每天早上一开机就登录博客园已经成了习惯, 总要先打开浏览器, 然后输入www.cnblogs.com,然后等待... ...
要是某天有火箭队的比赛, 还要去关注一下赛事情况: 先打开浏览器, 然后输入www.sohu.com,点NBA,然后... ...
哈哈, 还有一件少不了的事情,就是要登录电子油箱查看一下是否有新邮件...

这么多操作真是麻烦! 能不能通过点击一个按纽来简化这些操作呢?

前两天从同事(ZnS04)那里得到启示, 根据自动化测试的原理, 完全可以...

好了,下面就开始编写吧 ... ...

1).  新建一个 window application 工程.
2). 在窗体上添加3个Button,设置好属性, 如图:


3). 给工程添加2个引用 Microsoft.mshtml 和SHDocVw.dll
4). 编写代码

 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel;
 4using System.Data;
 5using System.Drawing;
 6using System.Text;
 7using System.Windows.Forms;
 8using System.Threading;
 9//添加引用
10using SHDocVw;
11using mshtml;
12
13namespace WebExplorer
14{
15    public partial class Form1 : Form
16    {
17        public Form1()
18        {
19            InitializeComponent();
20        }

21
22        /// <summary>
23        /// Redirect to the URL page.
24        /// </summary>
25        /// <param name="URL">Your wanted URL.</param>

26        public void GotoURL(string URL)
27        {
28            //实例化一个IE模型
29            SHDocVw.InternetExplorer IE = new InternetExplorer();            
30            IE.Visible = true;
31            object nullArg = null;
32            //引导到URL
33            IE.Navigate(URL, ref nullArg, ref nullArg, ref nullArg, ref nullArg);
34        }

35
36        private void gotocnBlogs_Click(object sender, EventArgs e)
37        {
38            this.GotoURL("www.cnblogs.com");
39        }

40
41        private void gotoNBA_Click(object sender, EventArgs e)
42        {
43            this.GotoURL("sports.sohu.com/nba"); 
44        }

45
46        private void gotoGmail_Click(object sender, EventArgs e)
47        {
48            try
49            {
50                
                        this.GotoURL("http://gmail.google.com");
55
56                Thread.Sleep(3000);
57                //得到IE的文档对象模型
58                mshtml.IHTMLDocument2 DOM = (mshtml.IHTMLDocument2)IE.Document;
59                //声明用户名
60                mshtml.IHTMLInputTextElement txtUserName = (mshtml.IHTMLInputTextElement)DOM.all.item("Email"null);
61                txtUserName.value = "YOUE USERNAME";
62                //声明密码
63                mshtml.IHTMLInputTextElement txtPwd = (mshtml.IHTMLInputTextElement)DOM.all.item("Passwd"null);
64                txtPwd.value = "PASSWORD";
65                //声明登录
66                mshtml.HTMLInputElement btnLogin = (mshtml.HTMLInputElement)DOM.all.item("null"0);
67                Thread.Sleep(1000);
68                btnLogin.click();
69            }

70            catch (Exception ex)
71            {
72
73            }

74        }

75    }

76}

5. 运行工程,点击上面的Button,OK!

需要说明两点:
1. 关于两个引用
   Microsoft.mshtml:这个引用可以从add reference->.NET中得到。
   SHDocVw.dll:这个引用在windows/system32目录下。
2.对上述dll进行引用后,即可实例化IE模型,通过构建页面元素进行操作。