HtmlUnit: A Simple Example: Check Yahoo Email---转载
1. src http://www.muneebahmad.com/index.php/archives/81
package com.examples.htmlunit; import java.io.IOException;
import java.net.URL;
import java.util.List; import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.RefreshHandler;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow; public class YahooMail { public static void main(String[] args) throws Exception { // Create and initialize WebClient object
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_2);
webClient.setThrowExceptionOnScriptError(false);
webClient.setRefreshHandler(new RefreshHandler() {
public void handleRefresh(Page page, URL url, int arg) throws IOException {
System.out.println("handleRefresh");
} }); // visit Yahoo Mail login page and get the Form object
HtmlPage page = (HtmlPage) webClient.getPage("https://login.yahoo.com/config/login_verify2?.intl=us&.src=ym");
HtmlForm form = page.getFormByName("login_form"); // Enter login and passwd
form.getInputByName("login").setValueAttribute("@@@@@@@");
form.getInputByName("passwd").setValueAttribute("@@@@@@@"); // Click "Sign In" button/link
page = (HtmlPage) form.getInputByValue("Sign In").click(); // Click "Inbox" link
HtmlAnchor anchor = (HtmlAnchor) page.getHtmlElementById("WelcomeInboxFolderLink");
page = (HtmlPage) anchor.click(); // Get the table object containing the mails
HtmlTable dataTable = (HtmlTable) page.getHtmlElementById("datatable"); // Go through each row and count the row with class=msgnew
int newMessageCount = 0;
List rows = (List) dataTable.getHtmlElementsByTagName("tr");
for (HtmlTableRow row: rows) {
if (row.getAttribute("class").equals("msgnew")) {
newMessageCount++;
}
} // Print the newMessageCount to screen
System.out.println("newMessageCount = " + newMessageCount); //System.out.println(page.asXml()); }
HtmlUnit: A Simple Example: Check Yahoo Email---转载的更多相关文章
- One simple health check for oracle with sql
There are some sqls which is used for check the oracle database's health condition. ------numbers of ...
- 转载:邮箱正则表达式Comparing E-mail Address Validating Regular Expressions
Comparing E-mail Address Validating Regular Expressions Updated: 2/3/2012 Summary This page compares ...
- Dynamics CRM 2011 2013-(An error occurred while opening mailbox xxx@xx.com Microsoft.Crm.Tools.Email.Providers.)
An error occurred while opening mailbox Microsoft.Crm.Tools.Email.Providers. Whenever I check how C ...
- 高并发网络编程之epoll详解(转载)
高并发网络编程之epoll详解(转载) 转载自:https://blog.csdn.net/shenya1314/article/details/73691088 在linux 没有实现epoll事件 ...
- error: C++ preprocessor "/lib/cpp" fails sanity check
在安装protobuf,知悉./Configure时候报错“error: C++ preprocessor "/lib/cpp" fails sanity check” 下面是转载 ...
- [Windows Azure] Building worker role B (email sender) for the Windows Azure Email Service application - 5 of 5.
Building worker role B (email sender) for the Windows Azure Email Service application - 5 of 5. This ...
- php等守护进程监控脚本(转载 http://www.9958.pw/post/php_script_scan)
此脚本用户守护监控进程的执行情况,因为有的时候,我们用各类开发语言做的守护进程可能会因为一些特殊情况被退出,所以此脚本就是为了重启这些进程 代码: #!/bin/bash EMAIL='9958_pw ...
- linux 常用端口【转载】
原文地址: http://blog.csdn.net/u013943420/article/details/65938696 一个计算机最多有65535个端口,端口不能重复.这65536个端口被分为两 ...
- JavaScript 检查 email 地址的正则表达式
JavaScript 检查 email 地址的正则表达式1.代码(1)<html><head><title>Checking an email address - ...
随机推荐
- 使用 X-Frame-Options 防止被iframe 造成跨域iframe 提交挂掉
Refused to display 'http://www.***.com/login/doLogin.html' in a frame because it set 'X-Frame-Optio ...
- 用CSS3把列表项目反转显示
忘了哪儿的一个题目来着,说是把 一个列表 给翻转序列显示,比如 : 有一个列表如图: 翻转为 回复里面有人机智的使用 CSS3 的 transform:rotate(180deg); 实现了,引发众 ...
- [ACM_数据结构] HDU 1166 敌兵布阵 线段树 或 树状数组
#include<iostream> #include<cstdio> #include<memory.h> using namespace std; ]; //- ...
- Spring Boot 2 实践记录之 封装依赖及尽可能不创建静态方法以避免在 Service 和 Controller 的单元测试中使用 Powermock
在前面的文章中(Spring Boot 2 实践记录之 Powermock 和 SpringBootTest)提到了使用 Powermock 结合 SpringBootTest.WebMvcTest ...
- CSharp如何自定义鼠标样式
一.如何设置鼠标样式? 在CSharp的WinForm开发中,可以通过下面的API设置鼠标样式: //把鼠标样式设置为十字(系统自带的一种鼠标样式) this.Cursor = Cursors.Cro ...
- 【原创】Self-Contained Container(自包含容器)
自包含容器是一种自包含的结构,很有趣.需要使用模板类,但只有在模板类型是该类的子类时,才使该类具有自包含的结构.这种结构从数据结构的角度看比较有用.通常的树类中的模板通常是“数据”的概念,即模板不参与 ...
- [C#学习笔记]类型对象指针和同步块索引
写在前面 看<CLR via C#>第四章时,看到了类型对象指针和同步块索引这两个概念,不知如何解释,查看过相关资料之后,在此记录. 类型对象指针 <CLR via C#>中的 ...
- LINQ to objects遇到的小坑
1.C#中LINQ to Objects中延迟查询的陷阱(其他类型的LINQ也基本一致) 之前在不了解LINQ延迟查询的时候,我使用下面的这种方式,将where语句的结果直接as为List<T& ...
- DotNetty 使用ByteToMessageDecoder 国家部标808协议封装
DotNetty 开源地址 https://github.com/Azure/DotNetty 个人博客地址 http://www.dncblogs.cn/Blog/ShowBlog/70 1.国 ...
- SQL Server2008 R2 数据库镜像实施手册(双机)
一.配置主备机 1. 服务器基本信息 主机名称为:HOST_A,IP地址为:192.168.1.155 备机名称为:HOST_B,IP地址为:192.168.1.156 二.主备实例互通 实现互通可以 ...