企业网站建设原因,19年做网站,企业网站的类型包括,网站界面设计实训报告选择操作网页
我用的edge#xff0c;谷歌我的版本太高没有对应的驱动… 下载Edge的驱动程序#xff0c;直接解压就好里面只有一个.exe文件 https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
复制即用#xff0c;看注释 import com.alibaba.fastjs…选择操作网页
我用的edge谷歌我的版本太高没有对应的驱动… 下载Edge的驱动程序直接解压就好里面只有一个.exe文件 https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
复制即用看注释 import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;public static String getCookie(){//写你下载驱动程序的位置System.setProperty(webdriver.edge.driver, D\\msedgedriver.exe);EdgeOptions options new EdgeOptions();options.addArguments(--remote-allow-origins*);EdgeDriver driver new EdgeDriver(options);//打开网页driver.navigate().to(https://user/index.html);try {Thread.sleep(1000); // 停止一秒单位是毫秒} catch (InterruptedException e) {e.printStackTrace();}// 找对应文件 点击driver.findElement(By.linkText(密码登录/注册)).click();try {Thread.sleep(1000); // 停止一秒单位是毫秒} catch (InterruptedException e) {e.printStackTrace();}driver.findElement(By.id(username)).sendKeys(1564885);driver.findElement(By.id(password)).sendKeys(41556x);driver.findElement(By.linkText(登录)).click();try {Thread.sleep(1000); // 停止一秒单位是毫秒} catch (InterruptedException e) {e.printStackTrace();}//登录后拿cookieWebDriver.Options manage driver.manage();SetCookie cookies manage.getCookies();String cookie ;for(Cookie c : cookies) {System.out.println(c.getName() - c.getValue());}//关闭页面看需求//driver.close();System.out.println(cookie);}