栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

添加使用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")


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/616198.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号