Last active
December 7, 2018 03:06
-
-
Save baobao/090223d1ff66d2341951c93ef4b09cba to your computer and use it in GitHub Desktop.
ログインサイトの画面キャプチャサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
# 1. ログインサイトにアクセス | |
url_login="http://uta.pw/sakusibbs/users.php?action=login&m=try" | |
driver = webdriver.PhantomJS() | |
driver.get(url_login) | |
print("ログインページへアクセス") | |
# 2. フォームにIDとパスワードをセットして送信 | |
USER = "ユーザーネーム" | |
PASS = "パスワード" | |
textbox = driver.find_element_by_id("user") | |
textbox.clear() | |
textbox.send_keys(USER) | |
textbox = driver.find_element_by_id("pass") | |
textbox.clear() | |
textbox.send_keys(PASS) | |
form = driver.find_element_by_css_selector("#loginForm form") | |
form.submit() | |
# 3. ログイン後HTMLからマイページURLを取得 | |
a = driver.find_element_by_css_selector(".islogin a") | |
url_mypage = a.get_attribute('href') | |
print("マイページURL",url_mypage) | |
# 4. ログイン後のURLの画面をキャプチャ | |
driver.get(url_mypage) | |
driver.save_screenshot("result.png") | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment