似乎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")
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)