1234567891011121314151617181920212223242526272829303132333435363738 |
- from selenium import webdriver
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.chrome.options import Options
- username = "apollo"
- password = "admin"
- chrome_options = Options()
- chrome_options.add_argument('--headless')
- driver = webdriver.Chrome("chromedriver", options=chrome_options)
- login_url = 'http://192.168.31.230:4379/signin'
- driver.get(login_url)
- # find username/email field and send the username itself to the input field
- login_form = driver.find_element(by=By.ID, value='login-form')
- login_form.find_element(by=By.NAME, value='username').send_keys(username)
- login_form.find_element(by=By.NAME, value='password').send_keys(password)
- login_form.find_element(by=By.ID, value='login-submit').click()
- WebDriverWait(driver=driver, timeout=10).until(
- lambda x: x.execute_script("return document.readyState === 'complete'")
- )
- cookies = driver.get_cookies()
- cookie_kv_str_list = ['{}={}'.format(c['name'], c['value']) for c in cookies]
- cookie_str = ';'.join(cookie_kv_str_list)
- print('cookie str:{}'.format(cookie_str))
- cookie_save_path = '../config/cookies'
- with open(cookie_save_path, mode='w') as cookie_file:
- cookie_file.write(cookie_str)
- print('done')
|