-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag_edit.py
119 lines (111 loc) · 5.66 KB
/
tag_edit.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
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 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_hidtag = driver.find_element_by_name("cts_hidesearchtagflag")
new_hidtext = driver.find_element_by_name("cts_hideindexflag")
if new_hidtag.is_selected():
new_hidtag.click()
if new_hidtext.is_selected():
new_hidtext.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()
if __name__ == "__main__":
userid = "lee"
userpw = "Mv3qKTUH"
driver = webdriver.Chrome()
driver.get("https://www.sci.kyoto-u.ac.jp/en/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)
pageNum = 0
for i in range(18):
#if i < 12:
# continue
viewPath = f"//*[@id=\"container\"]/table/tbody/tr[{3+i}]/td[7]/input[2]"
viewBtn = driver.find_element_by_xpath(viewPath)
viewBtn.click()
parentUrlCode = int(driver.current_url.split("=")[-1])
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
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
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
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()