Example usage for org.openqa.selenium Cookie getName

List of usage examples for org.openqa.selenium Cookie getName

Introduction

In this page you can find the example usage for org.openqa.selenium Cookie getName.

Prototype

public String getName() 

Source Link

Usage

From source file:zz.pseas.ghost.browser.BrowserFactory.java

License:Apache License

public static CookieStore getCookieStore(WebDriver driver) {
    CookieStore store = new BasicCookieStore();
    Set<Cookie> cs = driver.manage().getCookies();
    System.out.println(cs.size());
    for (Cookie c : cs) {
        BasicClientCookie c1 = new BasicClientCookie(c.getName(), c.getValue());
        if (c.getDomain() == null) {
            System.out.println(c.getName() + "->" + c.getValue());
        } else {//w  w  w  .j a  va  2 s. com
            System.out.println(c.getDomain());
        }

        c1.setDomain(c.getDomain() == null ? "my.alipay.com" : c.getDomain());
        c1.setPath(c.getPath());
        c1.setExpiryDate(c.getExpiry());
        store.addCookie(c1);
    }
    System.out.println(store.getCookies().size());
    return store;
}

From source file:zz.pseas.ghost.login.jd.JDCookie.java

License:Apache License

public boolean cookiesReady() {
    Set<Cookie> cookies = browser.manage().getCookies();
    Set<String> ks = new HashSet<String>();
    for (Cookie c : cookies) {
        String k = c.getName();
        ks.add(k);//from  w w  w. jav a2s  . com
    }

    for (String k : requiredCookies) {
        if (!ks.contains(k)) {
            return false;
        }
    }

    return true;

}

From source file:zz.pseas.ghost.login.jd.JDCookie.java

License:Apache License

public CookieStore supplyCookies() {
    if (!(paramDone && cookieDone)) {
        return null;
    }//from   w  w w.  j  ava2 s . c  o  m

    BasicCookieStore cookieStore = new BasicCookieStore();
    Set<Cookie> cookies = browser.manage().getCookies();
    for (Cookie c : cookies) {
        BasicClientCookie c1 = new BasicClientCookie(c.getName(), c.getValue());
        /*
        c1.setDomain(c.getDomain());
        c1.setPath(c.getPath());
        */
        c1.setExpiryDate(c.getExpiry());
        cookieStore.addCookie(c1);
    }
    return cookieStore;
}

From source file:zz.pseas.ghost.login.weibo.WeiboLogin.java

License:Apache License

public static void main(String[] args) {
    WebDriver driver = BrowserFactory.getIE();

    driver.get("http://weibo.com/");

    Set<Cookie> cookies = driver.manage().getCookies();
    BasicCookieStore cookieStore = new BasicCookieStore();
    for (Cookie c : cookies) {
        BasicClientCookie c1 = new BasicClientCookie(c.getName(), c.getValue());
        c1.setDomain(c.getDomain() == null ? "weibo" : c.getDomain());
        c1.setPath(c.getPath());//from w ww.  j a v  a 2s.  com
        Date d = c.getExpiry();
        if (d != null) {
            c1.setExpiryDate(d);
        }
        cookieStore.addCookie(c1);
    }
    driver.quit();

    GhostClient client = new GhostClient("utf-8", cookieStore);
    String url = "http://weibo.com/p/10080813dc27e2acb1441006674c8aa2ef07d4/followlist?page=1#Pl_Core_F4RightUserList__38";
    //HttpGet get = new HttpGet(url);
    String s = client.get(url);
    System.out.println(s);
    String next = StringUtil.regex(s, "(?<=replace\\(\").*?(?=\")");
    String html = client.get(next);
    System.out.println(html);
}

From source file:zz.pseas.ghost.utils.DownloadUtil.java

License:Apache License

public static CookieStore convertToCookieStore(Set<Cookie> cookies) {
    BasicCookieStore store = new BasicCookieStore();
    for (Cookie c : cookies) {
        BasicClientCookie c1 = new BasicClientCookie(c.getName(), c.getValue());
        c1.setDomain(c.getDomain());//from w ww  .j  a  v a 2  s  .c o m
        c1.setPath(c.getPath());
        c1.setExpiryDate(c.getExpiry());
        store.addCookie(c1);
    }
    return store;
}