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. Android-JVM中的多线程&垃圾回收

    Java语言是为数不多支持多线程技术的编程语言,而这多线程就不得不提到JVM虚拟机 先看代码案例:(JVM收垃圾) package android.java.thread; class Demo { ...

  2. C#扩展一个现有的类

    做个记录,写个示例 using System; class Rubbish { public void Say() { Console.Write("Hello"); } } st ...

  3. Android 标题栏(1)

    本文来自网易云社区 作者:孙有军 标题栏在每个应用中都有,有各种各样的标题栏,今天我们就主要来说说标题栏怎么做,主要内容涉及到自定义标题,ActionBar,Toolbar等知识. 自定义标题 几年前 ...

  4. Axure学习了解

    我这次介绍的原型设计工具为Axure 一.区域介绍 这是主界面: 左上区域显示原型的各个界面,可以添加新界面: 左中包含各种原型设计所包含的组件,例如文本框,图片等: 左下是各种模板,模板由自己设计, ...

  5. Flask从入门到精通之自定义错误界面

    如果你在浏览器的地址栏中输入了不可用的路由,那么会显示一个状态码为404 的错误页面.现在这个错误页面太简陋.平庸,而且样式和使用了Bootstrap 的页面不一致. 像常规路由一样,Flask 允许 ...

  6. 关于MySQL连接抛出Authentication Failed错误分析

    [问题描述] 在应用端,偶尔看到有如下报错: Authentication to host 'xxxx' for user 'yyyy' using method 'mysql_native_pass ...

  7. System Trace in Depth

    原理 使用 system trace 时,会记录最近 5s 的 kernel trace,然后分析下面的操作: Scheduling activity System calls Virtual mem ...

  8. python学习笔记02-编码

    ASCII码  255个  每一个占1个字节 8位 解决中文的问题:出现一张扩展表  支持中文的第一张表  gb2312  后来发展为GBK1.0 Gb18030 万国码:unicode 世界统一 存 ...

  9. Django中指定生成表名的方法

    在模型类中定义元类: class Meta: de_table = 'tableName' #指定表名

  10. 下载Centos7 64位镜像

    下载Centos7 64位镜像 1.打开Centos官网 打开Centos官方网站地址:https://www.centos.org/,点击Get CentOS Now 2.点击Minimal ISO ...