操作Cookie语法:get_cookies():获取所有Cookie;add_cookie(cookie_dic):添加cookie;delete_all_cookies():删除所有Cookie
from selenium import webdriver driver = webdriver.Chrome() driver.get("https://www.baidu.com") #获取所有cookie cookie = driver.get_cookies() print(cookie) #添加cookie driver.add_cookie({"name":"key-a","value":"key-b"}) for cookie in driver.get_cookies(): print("%s->%s" %(cookie['name'],cookie['value']))
调用javaScript:语法:execute_script()。JavaScript 语法:window.scrollTo(左边距,上边距)
from selenium import webdriver import time driver = webdriver.Chrome() driver.get("https://www.baidu.com") driver.set_window_size(800,600) driver.find_element_by_id("kw").send_keys("selenium") driver.find_element_by_id("su").click() js = "window.scrollTo(300,800);" time.sleep(3) driver.execute_script(js)