我正在使用 selenium webdriver与chrome webdriver。我得到了一个网址的driver.get(" ...")
和做一些东西和网页抓取(例如点击一些按钮,获得一些信息和登录到网站)。
当脚本运行并完成时,我想运行另一个脚本来继续上次打开的窗口(因此在这种情况下,我不必花费大量时间登录该站点,点击一些按钮,直到我到达我想要的地方)。例如imagin你想登录到你的gmail帐户,点击一些按钮到达你的邮箱,你的脚本就在这里完成。然后你想运行另一个脚本来逐个打开你的电子邮件。
driver = webdriver.Chrome()
driver.get("https://gmail.google.com/inbox/")
inbox_button = driver.find_element_by_xpath("//*[@id=":5a"]/div/div[2]/span/a']")
inbox_button.click()
# the code finishes successfully right here
我不想打开一个新的chrome驱动程序并再次逐行运行我的代码。我希望引用当前chrome驱动程序的内容。
1条答案
按热度按时间xa9qqrwz1#
您需要保存会话Cookie才能返回到以前的状态。您可以通过以下方式进行此操作
但是这种解决方案并不十分优雅,您可以使用pickle来存储和加载cookie