TA的每日心情 | 无聊 4 天前 |
---|
签到天数: 530 天 连续签到: 2 天 [LV.9]测试副司令
|
1测试积点
使用selenium模块登录163网易邮箱,在添加cookie的时候总是报各种各样的错误,比如:missing "cookie",mimatch"domain",等等。求解决
- from selenium import webdriver
- from selenium.webdriver import ChromeOptions
- import time
- import pickle
-
- option = ChromeOptions()
- option.add_experimental_option("excludeSwitches",["enable-automation"])
- bro = webdriver.Chrome(executable_path=r'C:\Users\Administrator\Desktop\chromedriver.exe')
- bro.get("https://mail.163.com/")
- bro.implicitly_wait('2.3')
- # bro.find_element(by='xpath',value='//*[@id="account-box"]')
- src = bro.find_element_by_tag_name('iframe')
- bro.switch_to.frame(src)
- bro.find_element_by_xpath('/html/body/div[2]/div[2]/div[2]/form/div/div[1]/div[2]/input').send_keys('***')
- bro.find_element_by_xpath('/html/body/div[2]/div[2]/div[2]/form/div/div[3]/div[2]/input[2]').send_keys('***')
- bro.find_element_by_xpath('/html/body/div[2]/div[2]/div[2]/form/div/div[8]/a').click()
- cookies = bro.get_cookies()
- with open('./163cookies.txt','wb') as fp:
- pickle.dump(cookies,fp)
- with open('./163cookies.txt','rb') as fp:
- cookies = pickle.load(fp)
- bro.get('https://mail.163.com/')
- bro.delete_all_cookies()
- bro.refresh()
- time.sleep(5)
- for cookie in cookies:
- bro.add_cookie(cookie)
- bro.refresh()
复制代码- Traceback (most recent call last):
- File "C:/Users/Administrator/Desktop/test.py", line 31, in <module>
- bro.add_cookie(cookie)
- File "D:\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1124, in add_cookie
- self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})
- File "D:\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute
- self.error_handler.check_response(response)
- File "D:\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
- raise exception_class(message, screen, stacktrace)
- selenium.common.exceptions.InvalidCookieDomainException: Message: invalid cookie domain: Cookie 'domain' mismatch
- (Session info: chrome=97.0.4692.71)
-
复制代码 我尝试删除domain,并添加也不行.
求解答
|
|