from selenium import webdriver headers = { "Cookie": "JSESSIONID=xxxxxxxx", } def login(): url = "www.baidu.com" browser = webdriver.Chrome() browser.get(url) browser.implicitly_wait(10) browser.find_element_by_xpath('//*[@id="loginid"]').send_keys('1233') browser.find_element_by_xpath('//*[@id="userpassword"]').send_keys('123') browser.find_element_by_xpath('//*[@id="login"]').click() time.sleep(5) # browser.find_element_by_xpath('//input[@class="zd_btn_cancle btn_submit"]').click() browser.find_element_by_xpath('//*[@id="portal11"]/div[2]/span[2]/span/span[1]').click() frame = browser.find_element_by_xpath('//*[@id="mainFrame"]') # 定位到iframe标签 browser.switch_to.frame(frame) # 这个地方即将刷新 time.sleep(1) browser.find_element_by_link_text('电子红本').click() time.sleep(3) browser.switch_to.window(browser.window_handles[1]) # 拿到第二页句柄 browser.find_element_by_xpath('//*[@id="welcomePage"]/div[1]').click() time.sleep(3) dic = browser.get_cookies() time.sleep(20)