添加使用Firefox Webdriver的Cookie,但不能在PhantomJS中使用

添加使用Firefox Webdriver的Cookie,但不能在PhantomJS中使用,第1张

添加使用Firefox Webdriver的Cookie,但不能在PhantomJS中使用

似乎PhantomJS驱动程序不支持某些键/值。为了克服这个问题,我将最重要的注入

execute_script

def save_cookies(driver, file_path):    LINE = "document.cookie = '{name}={value}; path={path}; domain={domain}; expires={expires}';n"    with open(file_path, 'w') as file :        for cookie in driver.get_cookies() : file.write(LINE.format(**cookie))def load_cookies(driver, file_path):    with open(file_path, 'r') as file:        driver.execute_script(file.read())from selenium import webdriverdriver = webdriver.PhantomJS()# load the domaindriver.get("https://stackoverflow.com/users/login")# save the cookies to a filesave_cookies(driver, r"cookies.js")# delete all the cookiesdriver.delete_all_cookies()# load the cookies from the fileload_cookies(driver, r"cookies.js")


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5622294.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存