Created
June 11, 2019 14:15
-
-
Save mkizka/a25516459c03d09912c1246afa7b85f2 to your computer and use it in GitHub Desktop.
Wimaxの通信量を監視するやつ
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
import os | |
import sys | |
from time import sleep | |
from datetime import datetime | |
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
options = webdriver.ChromeOptions() | |
options.add_argument('--headless') | |
options.add_argument('--log-level=3') | |
d = webdriver.Chrome(options=options, service_log_path=os.path.devnull) | |
print('ブラウザ起動') | |
def login(): | |
d.get('http://192.168.100.1') | |
WebDriverWait(d, 5).until( | |
EC.presence_of_element_located((By.ID, 'user_type')) | |
) | |
print('アクセス完了') | |
d.find_element_by_id('user_type').send_keys('admin') | |
d.find_element_by_id('input_password').send_keys('93682') | |
d.find_element_by_id('login').click() | |
WebDriverWait(d, 5).until( | |
lambda x: d.current_url == 'http://192.168.100.1/html/status.htm' | |
) | |
print('ログイン完了') | |
d.get('http://192.168.100.1/html/statistics.htm') | |
def show(): | |
WebDriverWait(d, 1.5).until( | |
lambda x: not d.find_element_by_id('label_usedData_yesterday').text == '' | |
) | |
old_today = '' | |
old_yesterday = '' | |
while True: | |
if not d.current_url == 'http://192.168.100.1/html/statistics.htm': | |
print('ログイン状態の解除を検出') | |
raise Exception | |
now_today = d.find_element_by_id('label_usedData_today').text | |
now_yesterday = d.find_element_by_id('label_usedData_yesterday').text | |
if not old_today == now_today or not old_yesterday == now_yesterday: | |
print(f'[{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}]前日までの3日間{now_yesterday}, 本日までの3日間{now_today}') | |
old_today = now_today | |
old_yesterday = now_yesterday | |
sleep(1) | |
if __name__ == '__main__': | |
login() | |
while True: | |
try: | |
show() | |
except KeyboardInterrupt: | |
break | |
except: | |
login() | |
print('ブラウザを終了中…') | |
d.quit() | |
input('キーを押して終了') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment