1.cookies
Cookie是储存在用户本地终端上的数据
帮助 Web 站点保存有关访问者的信息,方便用户的访问。如记住用户名密码实现自动登录
from selenium import webdriver import time #未登录获取cookie driver=webdriver.Firefox() print(driver.get_cookies()) #启动浏览器获取cookies为空 driver.get("https://www.taobao.com/") #打开主页后获取cookies print(driver.get_cookies()) #打印出未登陆的cookie #登陆后获取cookie driver.find_element_by_link_text("登录").click() all_h=driver.window_handles print(driver.title) driver.switch_to_window(all_h[1]) #获取list里面第二个直接切换 print(driver.title) time.sleep(3) driver.find_element_by_xpath(".//*[@id='J_QRCodeLogin']/div[5]/a[1]").click() time.sleep(3) driver.find_element_by_id("TPL_username_1").clear() driver.find_element_by_id("TPL_username_1").send_keys(u"帐户名") driver.find_element_by_xpath(".//*[@id='TPL_password_1']").send_keys("密码") time.sleep(3) driver.find_element_by_id("J_SubmitStatic").click() time.sleep(3) print(driver.get_cookies()) driver.delete_cookie(name=" ") #清除指定cookie print(driver.get_cookies()) driver.refresh() #driver.delete_all_cookies() #清除所有cookie后,cookies为空