问题
I'm using selenium for the past 1 month. I want to create some small applications using selenium. Selenium webdriver opens an incognito window when I run it. Is there any way to make it launch in normal window(i.e which has my accounts logged in)?
This is the code which I'm using : (python code in linux)
chromedriver = Path to chrome driver
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("http://www.gmail.com")
回答1:
If you want to re-use your login/authentication cookies, you can save the cookies and then load it again.
You can refer to this post:
To save cookies:
import pickle
import selenium.webdriver
driver = selenium.webdriver.Firefox()
driver.get("http://www.google.com")
pickle.dump( driver.get_cookies() , open("cookies.pkl","wb"))
To add back the cookies:
import pickle
import selenium.webdriver
driver = selenium.webdriver.Firefox()
driver.get("http://www.google.com")
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
driver.add_cookie(cookie)
If you want to load an extension when Chrome starts, you can refer to this post and this post.
来源:https://stackoverflow.com/questions/24754760/how-to-make-selenium-webdriver-open-in-google-chrome-without-incognito