I've been using Trend Micro's Password Manager until now. Sometimes Chrome extensions are useless, and I was wondering if something was wrong. Bitwarden was free and it felt good, so I decided to switch.
Output the password file to CSV with Password Manager I thought it would be a moment to transfer after importing with Bitwarden, Since Password Manager was not an option in the import option, I tried to automate it with Selenium.
https://vault.bitwarden.com/#/
Python + Selenium to go through all the automatic operations of Chrome https://qiita.com/memakura/items/20a02161fa7e18d8a693
Install Selenium with the following command.
pip install selenium
I tried to install chromedriver with pip install, In my case, the version did not match with Chrome and I got an error, so I have dropped the matching version of chromedriver from the following site.
http://chromedriver.chromium.org/downloads
After downloading, please place it wherever you like. I created and stored the following folders under the library.
/Library/ChromeDriver/chromedriver
This completes the Selenium setup.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains
import datetime
import csv
import codecs
driver = webdriver.Chrome(executable_path='/Library/ChromeDriver/chromedriver')
#Specify the URL of the website to access
driver.get('https://vault.bitwarden.com/#/')
#Wait 2 seconds after transitioning to the login screen
time.sleep(2)
#Close browser
driver.quit()
For those who pip installed the chrome driver
import chromedriver_binary
Please add.
You now have a program to access Bitwarden.
driver = webdriver.Chrome(executable_path='/Library/ChromeDriver/chromedriver')
#Specify the URL of the website to access
driver.get('https://vault.bitwarden.com/#/')
#Wait 2 seconds after transitioning to the login screen
time.sleep(2)
#Enter your login ID
login_id = driver.find_element_by_name("Email")
login_id.send_keys("My email address")
#Enter password
master_password = driver.find_element_by_name("MasterPassword")
master_password.send_keys("My password")
#Login button click
login_btn = driver.find_element_by_xpath("/html/body/app-root/app-frontend-layout/app-login/form/div/div/div/div/div[4]/button")
login_btn.click()
time.sleep(5)
#Close browser
driver.quit()
The login ID/password form is
find_element_by_name
You can find it at. Since the name was not specified for the login button, it is specified in XPATH.
Press the F12 button on your browser and use the developer tools to find the name or id of the location. It feels like specifying it with the corresponding "find_element_by ~".
You can now log in.
By the way, this CSV file has the following format.
Passwords.csv
Site name,Site URL,username,password
driver = webdriver.Chrome(executable_path='/Library/ChromeDriver/chromedriver')
#Specify the URL of the website to access
driver.get('https://vault.bitwarden.com/#/')
#Wait 2 seconds after transitioning to the login screen
time.sleep(2)
#Enter your login ID
login_id = driver.find_element_by_name("Email")
login_id.send_keys("My email address")
#Enter password
master_password = driver.find_element_by_name("MasterPassword")
master_password.send_keys("My password")
#Login button click
login_btn = driver.find_element_by_xpath("/html/body/app-root/app-frontend-layout/app-login/form/div/div/div/div/div[4]/button")
login_btn.click()
time.sleep(5)
#Read CSV file
#Since Japanese is handled by the site name, the character code is Shit-Select JIS
with codecs.open('CSV file PATH',"rb", "Shift-JIS", "ignore") as f:
for row in reader:
#If there is a header on the first line of the CSV file, skip reading below
next(reader)
#Login ID/Get the elements of each form in the same way as PW and click/Enter
#Item addition
add_item = driver.find_element_by_xpath("/html/body/app-root/app-user-layout/app-vault/div/div/div[2]/div/div/button")
add_item.click()
#Enter name
enter_name = driver.find_element_by_name("Name")
enter_name.send_keys(row[0])
print("I entered the name")
#Enter user name
enter_username = driver.find_elements_by_id("loginUsername")
enter_username[0].send_keys(row[2])
print("I entered my user name")
#Enter password
enter_password = driver.find_elements_by_id("loginPassword")
enter_password[0].send_keys(row[3])
print("I entered the password")
#Enter URL
enter_url = driver.find_elements_by_xpath("/html/body/app-root/app-user-layout/app-vault/app-modal/app-vault-add-edit/div/div/form/div[2]/div[5]/div[1]/div/input")
enter_url[0].send_keys(row[1])
print("I entered the URL")
#Click the save button
click_save = driver.find_elements_by_xpath("/html/body/app-root/app-user-layout/app-vault/app-modal/app-vault-add-edit/div/div/form/div[3]/button[1]/span")
click_save[0].click()
#Wait 2 seconds until the next input
time.sleep(2)
#Close browser
driver.quit()
Items that are not picked up by name or id are specified in XPATH.
enter_username[0].send_keys(row[2])
Things with [0] are necessary because the variable type is list. If you run it without this
AttributeError: 'list' object has no attribute 'send_keys',
I got the error.
With reference to this, I tried to imitate it for the time being. I'm not sure why, but it worked, so I left it for the time being. .. ..
https://programmersought.com/article/33681438536/
that's all.
AttributeError: 'list' object has no attribute 'send_keys', python+selenium Enables automatic login of QQ space pages. https://programmersought.com/article/33681438536/
Recommended Posts