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---转载的更多相关文章

  1. 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 ...

  2. 转载:邮箱正则表达式Comparing E-mail Address Validating Regular Expressions

    Comparing E-mail Address Validating Regular Expressions Updated: 2/3/2012 Summary This page compares ...

  3. 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 ...

  4. 高并发网络编程之epoll详解(转载)

    高并发网络编程之epoll详解(转载) 转载自:https://blog.csdn.net/shenya1314/article/details/73691088 在linux 没有实现epoll事件 ...

  5. error: C++ preprocessor "/lib/cpp" fails sanity check

    在安装protobuf,知悉./Configure时候报错“error: C++ preprocessor "/lib/cpp" fails sanity check” 下面是转载 ...

  6. [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 ...

  7. php等守护进程监控脚本(转载 http://www.9958.pw/post/php_script_scan)

    此脚本用户守护监控进程的执行情况,因为有的时候,我们用各类开发语言做的守护进程可能会因为一些特殊情况被退出,所以此脚本就是为了重启这些进程 代码: #!/bin/bash EMAIL='9958_pw ...

  8. linux 常用端口【转载】

    原文地址: http://blog.csdn.net/u013943420/article/details/65938696 一个计算机最多有65535个端口,端口不能重复.这65536个端口被分为两 ...

  9. JavaScript 检查 email 地址的正则表达式

    JavaScript 检查 email 地址的正则表达式​1.代码(1)<html><head><title>Checking an email address - ...

随机推荐

  1. Unity3D规则之Unity Root Motion / Bake into Pose 的问题

    参考: http://ru.unity3d-docs.com/Documentation/Manual/Animator.html http://ru.unity3d-docs.com/Documen ...

  2. Androd Studio测试

    测试的分类: 在软件开发领域,程序员开发编码后,需要测试部门的测试,才可以发布软件版本,所以对测试的概念需要了解: 黑盒测试:我的理解是,黑盒测试更多的是体力活,按照测试用例,在屏幕上不停的操作的方式 ...

  3. sun.jersey使用Jackson转换数据

    差点被com.sun.jersey自身的json转换吓死,遇到List等类型,会把这些也转换为json对象,而不是jsonarray. 被园里的同行拯救了,在web.xml中配置一下就ok. < ...

  4. Ruby on Rails 生成指定版本的 Rails 项目

    ruby-on-rails ruby 本地 Rails 默认5.1.6 版本 $ gem list --local rails (5.1.6, 5.1.5, 5.1.4) 使用 version 生成指 ...

  5. centos6.2 下安装并配置hadoop1.0.4(32位安装)

      一,环境准备 1.  集群内所有电脑需要设置防火墙,下面以master为例说明: 切换到root用户下,执行setup指令:

  6. spring3.2+mybatis3.2+maven整合

    用maven管理spring+mybatis的项目: 这里主要讲述的是maven中的pom.xml文件的配置,以及在maven构建过程中会碰到的几个问题(我用的是maven4.4的版本): 首先一步一 ...

  7. react.js 点击事件传递参数的方法

    <button onClick={this.handleClick.bind(this, props0, props1, ...}></button> handleClick( ...

  8. SVN图形客户端上传静态库.a文件失败

    1.原因客户端未添加静态库 2.解决办法 到项目静态库所在目录用命令行添加静态库文件 svn add ****.a 3.可能存在问题 Mac OS的自带SVN版本过低不能添加,报错如下: svn: E ...

  9. 一步一步教你使用 LSMW 批量处理数据

    保存退出 输入完后,保存退出

  10. 【LeetCode】462. 最少移动次数使数组元素相等 II

    给定一个非空整数数组,找到使所有数组元素相等所需的最小移动数,其中每次移动可将选定的一个元素加1或减1. 您可以假设数组的长度最多为10000. 例如: 输入: [1,2,3] 输出: 2 说明: 只 ...