-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhealthy_everyday.py
executable file
·58 lines (46 loc) · 1.69 KB
/
healthy_everyday.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
#!/home/fang/anaconda3/bin/python
import os
import random
import sys
import time
from datetime import datetime
from selenium import webdriver
from selenium.common.exceptions import UnexpectedAlertPresentException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from out_every_day import click_select_list
def upload(username, password):
option = webdriver.ChromeOptions()
option.add_argument('headless')
# login
driver = webdriver.Chrome(options=option)
driver.get(address)
wait = WebDriverWait(driver, 60)
elem = driver.find_element_by_id('un')
elem.send_keys(username)
elem = driver.find_element_by_id('pd')
elem.send_keys(password)
# commit
driver.get(address)
wait.until(EC.frame_to_be_available_and_switch_to_it('formIframe'))
click_select_list(driver, "TW1", random.randint(1, 6))
click_select_list(driver, "TW2", random.randint(1, 6))
click_select_list(driver, "TW3", random.randint(1, 6))
driver.switch_to.default_content()
commit = wait.until(EC.element_to_be_clickable((By.ID, 'commit')))
commit.click()
# time.sleep(1000)
driver.close()
if __name__ == '__main__':
dir_name = os.path.dirname(sys.argv[0])
address = open(os.path.join(dir_name, 'address.txt')).readline()
user_info = open(os.path.join(dir_name, 'user_info.txt'))
print(datetime.today())
for i in user_info:
p = user_info.readline().strip('\n') + '\n'
try:
upload(i, p)
print(i + " 填报完成")
except UnexpectedAlertPresentException:
print(i + " 已经填报")