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 - ...
随机推荐
- [c# 20问] 4.Console应用获取执行路径
一行代码可以搞定了~ static void GetAppPath() { string path = System.Reflection.Assembly.GetExecutingAssembly( ...
- C# 获取相对路径(绝对路径转相对路径)
这个的方法有很多吧. 1. 用PInvok调用Windows API的PathRelativePathTo 2. 自行处理字符串 3. 利用Uri 前两种就不说了,觉得有点麻烦,想了解的同学,自已,百 ...
- 如何使用T-SQL备份还原数据库及c#如何调用执行?
准备材料:Microsoft SQL Server一部.需要还原的bak文件一只 一.备份 数据库备份语句:user master backup database 数据库名 to disk='保存路径 ...
- IIS发布网站之后,页面图片和js未加载出错
[IIS相关]mvc做的web发布之后,运行之后界面上的图片和js都没有加载出来. 解决方案:安装IIS的时候需要勾选ASP选项,否则会出现这种情况. 如果项目是用.Netframework ...
- 巧用XML配置校验导入Excel的列数据格式
<?xml version="1.0"?> <ColumnsSeting xmlns:xsd="http://www.w3.org/2001/XMLSc ...
- java入门——面向对象
简介 对象具有自己的状态和行为: 描述一个对象具有什么状态和行为的过程叫做建模,不同的意图下我们对同一个事物的描述会产生不同的模型. 类 类描述一类对象的状态和行为的模板.可以把类想象成一个汽车设计图 ...
- Python3.5 学习八
#动态导入 官方建议import importlibimport_str="lib.aa"lib=importlib.import_module(import_str)obj=li ...
- 内核格式化(C++)
参考<C++ Primer Plus>P788 iostream族支持 程序 与 终端 之间的I/O fstream族支持 程序 与 文件 之间的I/O sstream族支持 程序 与 s ...
- HttpClient调用IdentityServer4获取Token并调用接口
using System; using System.Net.Http; using IdentityModel.Client; namespace ClientCredential { class ...
- iOS 关于布局问题的一些认识
///更新约束和布局 更新约束布局相关的API - (void)updateConstraintsIfNeeded 调用此方法,如果有标记为需要重新布局的约束,则立即进行重新布局,内部会调用upda ...