使用htmlunit访问hotmail的垃圾文件夹

时间:2012-06-27 11:51:10

标签: java htmlunit hotmail

我想在java中使用htmlUnit访问hotmail帐户的垃圾文件夹,因为htmlunit似乎支持javascript。使用以下代码,我可以访问收件箱文件夹,但从中我想获取垃圾文件夹。我发现页面左侧显示的“垃圾”是一个标签。所以我试图访问标签然后想点击它。但是我无法从HtmlPage访问“垃圾”标签。垃圾标签的Html代码如下所示。

<span class="FolderLabel">
Junk
<span style="display:none;">
(
<span class="count"></span>
)
</span>
</span>
</span>

以下是我用来获取垃圾文件夹的代码:

 import java.io.IOException;
    import java.net.URL;

    import org.w3c.dom.Node;

    import com.gargoylesoftware.htmlunit.WebClient;
    import com.gargoylesoftware.htmlunit.html.DomNodeList;
    import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
    import com.gargoylesoftware.htmlunit.html.HtmlElement;

import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlLabel;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;



public class TesthtmlUnit {
     public static void main(String[] args) throws IOException
     {
         final WebClient webClient = new WebClient();

            // Get the first page
            final HtmlPage page1 = webClient.getPage("https://login.live.com/ppsecure/post.srf");
            webClient.setThrowExceptionOnScriptError(false);

            final HtmlForm form = page1.getFormByName("f1");

            final HtmlSubmitInput button = form.getInputByName("SI");
            final HtmlTextInput uname = form.getInputByName("login");
            final HtmlPasswordInput pwd = form.getInputByName("passwd");
            // Change the value of the text field
            uname.setValueAttribute("emailid@hotmail.com");
            pwd.setValueAttribute("pwd");

            HtmlPage page2 = button.click();
            //System.out.println(page2.asXml());

            HtmlAnchor inbox = (HtmlAnchor) page2.getAnchorByHref("http://mail.live.com/?rru=inbox");
            page2 = (HtmlPage) inbox.click();
            //System.out.println(page2.asXml());

            //CLICK ON JUNK LABEL
          //here I want access label "junk" from page2 


            webClient.closeAllWindows();
     }

}

有人知道如何点击垃圾文件夹吗?我经历了htmlpage提供的方法,但找不到办法。

对此我感激不尽。

感谢。

0 个答案:

没有答案