-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeReserveSystem.py
210 lines (157 loc) · 6.4 KB
/
peReserveSystem.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
from selenium import webdriver
import getpass
import requests
from bs4 import BeautifulSoup
import time
from selenium.webdriver.chrome.options import Options
url = "https://wellness.sfc.keio.ac.jp/v3/index.php?page=top&limit=9999&semester=20185&lang=ja"
html = requests.get(url).text
soup = BeautifulSoup(html, "html.parser")
span = soup.find_all("td")
state = 0
state2 = 0
sports = []
periods = []
dates = []
currentDate = ""
currentPeriod = ""
currentSport = ""
variousThings = ""
for tag in span:
try:
string_ = tag.get("class").pop(0)
if string_ in "w3-hide-small":
state = state + 1
if ((state-1)%5) == 0:
state2 = state2 + 1
variousThings = tag.string
if variousThings != None :
currentDate = variousThings
dates.append(currentDate)
if ((state-2)%5) == 0:
variousThings = tag.string
if variousThings != None :
currentPeriod = variousThings
periods.append(currentPeriod)
if ((state-3)%5) == 0:
if "セミエキスパート" in str(tag):
currentSport = str(tag).replace('<td class="">', '').replace('<em>*組</em></td>', '').strip()
sports.append(str(tag).replace('<td class="">', '').replace('<em>*組</em></td>', '').strip())
else:
currentSport = tag.string
sports.append(tag.string)
print(str(state2)+ ". " + currentDate + " " + currentPeriod+ " " + currentSport)
except:
pass
username = input("ログイン名:")
password = getpass.getpass()
chosenNumber = int(input("番号:"))
print(dates[chosenNumber-1] + " " + periods[chosenNumber-1] + " " + sports[chosenNumber - 1])
options = Options()
# ヘッドレスモードを有効にする(次の行をコメントアウトすると画面が表示される)。
#options.add_argument('--headless')
# ChromeのWebDriverオブジェクトを作成する。
browser = webdriver.Chrome(chrome_options=options)
loginUrl= "https://wellness.sfc.keio.ac.jp/v3/index.php?page=top&limit=9999&semester=20185&lang=ja"
browser.get(loginUrl)
userNameField = browser.find_element_by_xpath('//*[@id="maincontents"]/form/div/table/tbody/tr[1]/td/input')
userNameField.send_keys(username)
passwordField = browser.find_element_by_xpath('//*[@id="maincontents"]/form/div/table/tbody/tr[2]/td/input')
passwordField.send_keys(password)
submitButton = browser.find_element_by_xpath('//*[@id="maincontents"]/form/div/table/tbody/tr[3]/td[2]/input')
submitButton.click()
reserveButton = browser.find_element_by_xpath('//*[@id="navbar"]/div/a[1]')
reserveButton.click()
browser.get(browser.current_url + "&limit=9999")
url = browser.current_url
html = requests.get(url).text
soup = BeautifulSoup(html, "html.parser")
span = soup.find_all("td")
state = 0
sports2 = []
currentDate = ""
currentPeriod = ""
currentSport = ""
variousThings = ""
for tag in span:
try:
string_ = tag.get("class").pop(0)
if string_ in "w3-hide-small":
state = state + 1
if ((state-1)%5) == 0:
variousThings = tag.string
if variousThings != None :
currentDate = variousThings
if ((state-2)%5) == 0:
variousThings = tag.string
if variousThings != None :
currentPeriod = variousThings
if ((state-3)%5) == 0:
if "セミエキスパート" in str(tag):
currentSport = str(tag).replace('<td class="">', '').replace('<em>*組</em></td>', '').strip()
sports2.append(str(tag).replace('<td class="">', '').replace('<em>*組</em></td>', '').strip())
else:
currentSport = tag.string
sports2.append(tag.string)
if currentDate == dates[chosenNumber - 1] :
if currentPeriod == periods[chosenNumber - 1] :
if currentSport == sports[chosenNumber - 1] :
break
except:
pass
sportState = str(len(sports2))
reserveSportButton = browser.find_element_by_xpath('//*[@id="maincontents"]/div[5]/table/tbody/tr[' + sportState + ']/td[8]/a').get_attribute('href')
browser.get(reserveSportButton)
reserveButton = browser.find_element_by_xpath('//*[@id="maincontents"]/form/p/input[1]')
browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
reserveButton.click()
reserveButton = browser.find_element_by_xpath('//*[@id="maincontents"]/form/p/input[1]')
browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
reserveButton.click()
print("処理が完了しました")
confirmButton = browser.find_element_by_xpath('//*[@id="navbar"]/div/a[2]')
confirmButton.click()
state = 0
state2 = 0
currentDate2 = ""
currentPeriod2 = ""
currentSport2 = ""
variousThings = ""
reserveState = False
print("予約している授業一覧")
print("---------------------------------")
url = browser.current_url
html = requests.get(url).text
soup = BeautifulSoup(html, "html.parser")
span = soup.find_all("td")
for tag in span:
try:
string_ = tag.get("class").pop(0)
if string_ in "w3-hide-small":
state = state + 1
if ((state-1)%6) == 0:
state2 = state2 + 1
variousThings = tag.string
if variousThings != None :
currentDate2 = variousThings
if ((state-2)%6) == 0:
variousThings = tag.string
if variousThings != None :
currentPeriod2 = variousThings
if ((state-3)%6) == 0:
if "セミエキスパート" in str(tag):
currentSport2 = str(tag).replace('<td class="">', '').replace('<em>*組</em></td>', '').strip()
else:
currentSport2 = tag.string
print(str(state2)+ ". " + currentDate2 + " " + currentPeriod2+ " " + currentSport2)
if currentDate == currentDate2 :
if currentPeriod == currentPeriod2 :
if currentSport == currentSport2 :
reserveState = True
except:
pass
browser.quit()
if reserveState :
print("予約に成功しました")
else:
print("予約に失敗しました")