Python script for HINET login without SSO/logout (Hiroshima-univ)
Zum Üben von Python und Selen Zum An- und Abmelden der Nicht-SSO-Authentifizierung der Hiroshima University am Terminal Schrieb das Programm
Anmeldung)
./nsso.py login
Ausloggen
./nsso.py logout
Wenn Sie die X11-Weiterleitung nicht verwenden möchten
DISPLAY=unix:0.0 ./nsso.py login
Und...
nsso.py
#!/usr/bin/env python2
# coding: utf-8
# program for Only "without SSO" !!!!!!
#sudo pip install selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from getpass import getpass
import sys
#import re
# https://idp.media.hiroshima-u.ac.jp/idp/Authn/UserPassword
# https://hinet.hiroshima-u.ac.jp/loginweb.html
def logout(browser):
try:
browser.get('https://hinet.hiroshima-u.ac.jp/cgi-bin/Logout.cgi')
browser.close()
print "logout success!"
except:
print "ERROR!!!"
browser.close()
def without_sso_login(browser):
try:
browser.get('https://hinet.hiroshima-u.ac.jp/login_frame.html')
username = raw_input("Username :")
password = getpass( "Password :")
browser.find_element(By.NAME,"uid").send_keys(username)
browser.find_element(By.NAME,"pwd").send_keys(password)
#raw_input("y:")
browser.find_element_by_xpath("//input[@type='submit']").click()
page=browser.page_source
if page.count("Login succeeded") >= 1 :
print "login success!"
else:
print "login filure..."
browser.close()
except:
print "ERROR!!!"
browser.close()
if __name__ == '__main__':
param = sys.argv
print "login : [./nsso.py] or [./nsso.py login]"
print "logout: [./nsso.py logout]"
print "SSO :https://idp.media.hiroshima-u.ac.jp/idp/Authn/UserPassword"
print "Not SSO:https://hinet.hiroshima-u.ac.jp/loginweb.html"
print " ---> https://hinet.hiroshima-u.ac.jp/login_frame.html"
browser = webdriver.Firefox()
if len(param) == 2 and param[1]=="logout":
print "=======LOGOUT========="
logout(browser)
print "======= END ========="
elif (len(param)==2 and param[1]=="login") or len(param)==1:
print "=======LOGIN========="
without_sso_login(browser)
print "======= END ========="
Recommended Posts