-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathAutoLoad.py
62 lines (51 loc) · 1.81 KB
/
AutoLoad.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Create date: 2021.08.31
# Author: Sunhr
# Keep BIT-Web online
import time
import random
import argparse
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import FirefoxOptions,ChromeOptions
def loopLoad(usrname,passwd,browserChoice='firefox'):
while(1):
if browserChoice == 'firefox':
opts = FirefoxOptions()
opts.add_argument("--headless")
browser = webdriver.Firefox(options=opts)
elif browserChoice == 'chrome':
opts = ChromeOptions()
opts.add_argument("--headless")
browser = webdriver.Chrome(options=opts)
time.sleep(1)
el = lambda id : browser.find_element(By.ID, id)
try:
browser.get('http://10.0.0.55/')
time.sleep(1)
try:
if el("logout"):
print("Bit-Web still OK!")
browser.close()
time.sleep(random.randint(3,7))
continue
except:
el("username").clear()
el("password").clear()
el("username").send_keys(usrname)
el("password").send_keys(passwd)
el("login").click()
time.sleep(2)
print("Bit-Web OK!")
except:
browser.close()
print("Bit-Web Failed!")
continue
if __name__ == '__main__':
browerDict = {'1':'firefox','2':'chrome'}
browerIdx = input('Please choose your brower number ( 1 for Firefox; 2 for Chrome ):')
usrname = input("Please input username: ")
passwd = input("Please input passwd: ")
loopLoad(usrname,passwd,browerDict[browerIdx])
# usrname = args.usrname
# passwd = args.passwd
# print(usrname,passwd)