YOUDAO_MOBILE_ACCESS_TYPE -> 1
DICT_UGC -> be3af0da19b5c5e6aa4e17bd8d90b28a|
OUTFOX_SEARCH_USER_ID -> 269759546@218.17.197.195
JSESSIONID -> abcR9UzO8h_WI9eyr3gow
___rl__test__cookies -> 1526976028013
OUTFOX_SEARCH_USER_ID_NCOO -> 278126924.1146677
key-aaaaaaa -> value-bbbb
Traceback (most recent call last):
File "D:/aasoftcfl/python/cflproject/chrome_13_cookie_2.py", line 20, in <module>
driver.delete_cookie("CookieName")
File "D:\aasoftcfl\python\lib\site-packages\selenium-3.11.0-py3.6.egg\selenium\webdriver\remote\webdriver.py", line 847, in delete_cookie
self.execute(Command.DELETE_COOKIE, {'name': name})
File "D:\aasoftcfl\python\lib\site-packages\selenium-3.11.0-py3.6.egg\selenium\webdriver\remote\webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "D:\aasoftcfl\python\lib\site-packages\selenium-3.11.0-py3.6.egg\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: TypeError: class constructors must be invoked with |new|
#coding=utf-8 from selenium import webdriver import time driver = webdriver.Firefox() driver.get("http://www.youdao.com") #向cookie的name 和value添加会话信息。 driver.add_cookie({'name':'key-aaaaaaa', 'value':'value-bbbb'}) #遍历cookies中的name 和value信息打印,当然还有上面添加的信息 for cookie in driver.get_cookies(): print "%s -> %s" % (cookie['name'], cookie['value']) # 下面可以通过两种方式删除cookie # 删除一个特定的cookie driver.delete_cookie("CookieName") # 删除所有cookie driver.delete_all_cookies() time.sleep(2) driver.close()
原来的代码修改为下列代码,可运行通过;
#coding=utf-8 from selenium import webdriver import time driver = webdriver.Firefox() driver.get("http://www.youdao.com") #向cookie的name 和value添加会话信息。 driver.add_cookie({'name':'key-aaaaaaa', 'value':'value-bbbb'}) #遍历cookies中的name 和value信息打印,当然还有上面添加的信息 for cookie in driver.get_cookies(): print ("%s -> %s" % (cookie['name'], cookie['value'])) # 下面可以通过两种方式删除cookie # 删除一个特定的cookie driver.delete_cookie("key-aaaaaaa") #遍历cookies中的name 和value信息打印,当然还有上面添加的信息 for cookie in driver.get_cookies(): print ("%s -> %s" % (cookie['name'], cookie['value'])) # 删除所有cookie driver.delete_all_cookies() time.sleep(2) driver.close()
运行结果如下:
======= RESTART: D:/aasoftcfl/python/cflproject/chrome_13_cookie_2.py =======
YOUDAO_MOBILE_ACCESS_TYPE -> 1
DICT_UGC -> be3af0da19b5c5e6aa4e17bd8d90b28a|
OUTFOX_SEARCH_USER_ID -> 217191388@119.29.106.224
JSESSIONID -> abcc-gYQXugNy-SCKelow
___rl__test__cookies -> 1527046620618
OUTFOX_SEARCH_USER_ID_NCOO -> 16441829.420830978
key-aaaaaaa -> value-bbbb
YOUDAO_MOBILE_ACCESS_TYPE -> 1
DICT_UGC -> be3af0da19b5c5e6aa4e17bd8d90b28a|
OUTFOX_SEARCH_USER_ID -> 217191388@119.29.106.224
JSESSIONID -> abcc-gYQXugNy-SCKelow
___rl__test__cookies -> 1527046620618
OUTFOX_SEARCH_USER_ID_NCOO -> 16441829.420830978
>>>
学习路径:http://www.cnblogs.com/fnng/p/3269450.html