栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java小程序:阿里巴巴自动登入获取cookie2

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java小程序:阿里巴巴自动登入获取cookie2

1.自动化依赖以及谷歌驱动依赖


    com.google.zxing
    core
    3.0.0


    com.google.zxing
    javase
    3.0.0




    org.seleniumhq.selenium
    selenium-java
    3.9.0

2.下载谷歌驱动http://chromedriver.storage.googleapis.com/index.html

3.直接上代码

System.setProperty("webdriver.chrome.driver", "D:\lixiao\tool\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(false);
// 添加浏览器的伪装信息
chromeOptions.setExperimentalOption("useAutomationExtension", false);
chromeOptions.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
chromeOptions.addArguments("--disable-blink-features=AutomationControlled");
WebDriver driver = new ChromeDriver(chromeOptions);
try {

    driver.get("https://passport.alibaba.com/icbu_login.htm?return_url=https%3A%2F%2Fdata.alibaba.com%2F");

    Thread.sleep(1000);
    driver.findElement(By.id("fm-login-id")).sendKeys(acount);

    Thread.sleep(1000);
    driver.findElement(By.id("fm-login-password")).sendKeys(password);


    Thread.sleep(5000);
    WebElement loginButton =driver.findElement(By.id("fm-login-submit"));
    loginButton.click();
    Thread.sleep(1000);
    Set coo =driver.manage().getCookies();
    for (Cookie cookie : coo) {
        if(cookie.getName().equals("cookie2")){
            System.out.println("登录成功"+cookie.getValue());
            return cookie.getValue();
        }
    }
} catch (InterruptedException e) {
    e.printStackTrace();
}finally {
    driver.close();
    driver.quit();
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/946750.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号