-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkyutube_jp_school.py
163 lines (157 loc) · 9.06 KB
/
kyutube_jp_school.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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
import re
import chromedriver_binary
import urllib3, time
from urllib3.exceptions import InsecureRequestWarning
urllib3.disable_warnings(InsecureRequestWarning)
def page_edit(driver):
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.NAME, "form1")))
new_main_checkbox = driver.find_element_by_xpath("//*[@id=\"container\"]/form/table[1]/tbody/tr[6]/td/label/input")
if not new_main_checkbox.is_selected():
driver.back()
return
else:
new_main_checkbox.click()
try:
new_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[3]")
new_confirm.click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "preview")))
new_confirm_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
new_confirm_confirm.click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "message")))
new_confirm_back = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input")
new_confirm_back.click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "ctlr-list")))
except:
new_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
new_confirm.click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "preview")))
new_confirm_confirm = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input[2]")
new_confirm_confirm.click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "message")))
new_confirm_back = driver.find_element_by_xpath("//*[@id=\"container\"]/form/div/input")
new_confirm_back.click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "ctlr-list")))
def login(driver, userid, userpw):
sci_admin_id = driver.find_element_by_name("act_id")
sci_admin_pw = driver.find_element_by_name("act_passwd")
sci_admin_id.send_keys(userid)
sci_admin_pw.send_keys(userpw)
sci_admin_login = driver.find_element_by_xpath("/html/body/form/div/input")
sci_admin_login.click()
def main(lang):
userid = "lee"
userpw = "Mv3qKTUH"
driver = webdriver.Chrome()
driver.get("https://www.sci.kyoto-u.ac.jp/"+lang+"/admin/")
login(driver, userid, userpw)
time.sleep(0.3)
research_btn = driver.find_element_by_xpath("//*[@id=\"container\"]/table/tbody/tr[4]/td[7]/input[2]")
research_btn.click()
time.sleep(0.3)
kyutube_btn = driver.find_element_by_xpath("//*[@id=\"container\"]/table/tbody/tr[10]/td[7]/input[2]")
kyutube_btn.click()
time.sleep(0.3)
for i in range(18):
if i < 15:
continue
viewPath = f"//*[@id=\"container\"]/table/tbody/tr[{3+i}]/td[7]/input[2]"
viewBtn = driver.find_element_by_xpath(viewPath)
viewBtn.click()
try:
pageIndex = driver.find_element_by_xpath("//*[@id=\"container\"]/div[3]/span").text.split(":")[1]
pageIndex = int(pageIndex[:-1].strip())//25 + 1
print(f"Index {i} Total page: {pageIndex}")
if pageIndex < 10:
for j in range(pageIndex):
pageBtn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/div[3]/ul/li[{2+j}]")
pageBtn.click()
time.sleep(0.3)
lineIndex = driver.find_elements_by_css_selector("#container > table > tbody > tr")
print(f"Page {j+1} Line number: {len(lineIndex)-1}")
for k in range(len(lineIndex)):
if k == 0:
continue
file_name = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{k+1}]/td[4]")
if 'index' in file_name.text:
edit_btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{k+1}]/td[7]/input[1]")
edit_btn.click()
page_edit(driver)
list_btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{k+1}]/td[7]/input[2]")
list_btn.click()
lineIndex_sib = driver.find_elements_by_css_selector("#container > table > tbody > tr")
for l in range(len(lineIndex_sib)-1):
edit_btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{l+2}]/td[7]/input[1]")
edit_btn.click()
page_edit(driver)
back_btn = driver.find_element_by_xpath("//*[@id=\"container\"]/div[1]/span[4]/a")
back_btn.click()
else:
edit_btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{k+1}]/td[7]/input[1]")
edit_btn.click()
page_edit(driver)
else:
for j in range(pageIndex):
if j == 4 or j == 5 or j == 6:
j = 4
elif j > 6:
j = j - 2
pageBtn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/div[3]/ul/li[{2+j}]")
pageBtn.click()
time.sleep(0.3)
lineIndex = driver.find_elements_by_css_selector("#container > table > tbody > tr")
print(f"Page {j+1} Line number: {len(lineIndex)-1}")
for k in range(len(lineIndex)):
if k == 0:
continue
file_name = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{k+1}]/td[4]")
if 'index' in file_name.text:
edit_btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{k+1}]/td[7]/input[1]")
edit_btn.click()
page_edit(driver)
list_btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{k+1}]/td[7]/input[2]")
list_btn.click()
lineIndex_sib = driver.find_elements_by_css_selector("#container > table > tbody > tr")
for l in range(len(lineIndex_sib)-1):
edit_btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{l+2}]/td[7]/input[1]")
edit_btn.click()
page_edit(driver)
back_btn = driver.find_element_by_xpath("//*[@id=\"container\"]/div[1]/span[4]/a")
back_btn.click()
else:
edit_btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{k+1}]/td[7]/input[1]")
edit_btn.click()
page_edit(driver)
except:
print(f"Index {i} Total page: 1")
lineIndex = driver.find_elements_by_css_selector("#container > table > tbody > tr")
print(f"Line number: {len(lineIndex)-1}")
for k in range(len(lineIndex)):
if k == 0:
continue
file_name = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{k+1}]/td[4]")
if 'index' in file_name.text:
edit_btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{k+1}]/td[7]/input[1]")
edit_btn.click()
page_edit(driver)
list_btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{k+1}]/td[7]/input[2]")
list_btn.click()
lineIndex_sib = driver.find_elements_by_css_selector("#container > table > tbody > tr")
for l in range(len(lineIndex_sib)-1):
edit_btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{l+2}]/td[7]/input[1]")
edit_btn.click()
page_edit(driver)
back_btn = driver.find_element_by_xpath("//*[@id=\"container\"]/div[1]/span[4]/a")
back_btn.click()
else:
edit_btn = driver.find_element_by_xpath(f"//*[@id=\"container\"]/table/tbody/tr[{k+1}]/td[7]/input[1]")
edit_btn.click()
page_edit(driver)
back = driver.find_element_by_xpath("//*[@id=\"container\"]/div[1]/span[3]/a")
back.click()
driver.quit()
if __name__ == "__main__":
main("en")