Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
57
Help us understand the problem. What is going on with this article?
@shota-nekoneko

python × seleniumでID/PASS入力必要な画面に自動ログインしてみた

More than 3 years have passed since last update.

はじめに

python × seleniumでID/PASS入力必要な画面に自動ログインを試した際の自分的なメモとなります。

参考にさせて頂いた記事

コード

login.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

options = Options()
options.binary_location = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'

driver = webdriver.Chrome(chrome_options=options)
driver.get('対象のURL')

# ID/PASSを入力
id = driver.find_element_by_id("ユーザID入力フィールドの要素")
id.send_keys("実際のID")
password = driver.find_element_by_id("パスワード入力フィールドの要素")
password.send_keys("実際のPASS")

time.sleep(1)

# ログインボタンをクリック
login_button = driver.find_element_by_name("ログインボタンの要素")
login_button.click()

# サイト内で他の画面に遷移させたければ
driver.get('画面遷移させたいURL')
57
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
shota-nekoneko
猫大好きおっさん

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
57
Help us understand the problem. What is going on with this article?