| Date: 2020/01/19
| Presenter: Chia
我的密碼
import requests
from bs4 import BeautifulSoup
# ...
@handler.add(MessageEvent, message=TextMessage)
def handle_message(event):
if '成績' in event.message.text:
raw_msg = event.message.text
print(raw_msg)
other, studentID, studentPW = raw_msg.split('\n')
print(other, studentID, studentPW)
if studentID != None and studentPW != None:
payload = {'mail_id': studentID, 'mail_pwd': studentPW}
rs = requests.session()
res = rs.post('http://stu.fju.edu.tw/stusql/SingleSignOn/StuScore/SSO_stu_login.asp', data = payload)
res2 = rs.get('http://stu.fju.edu.tw/stusql/SingleSignOn/StuScore/stu_scoreter.asp')
soup = BeautifulSoup(res2.content, "html.parser")
all_td1 = soup.find_all('td', {'align': 'left', 'valign': None})
list1 = []
for obj in all_td1:
list1.append(obj.contents[0].strip())
print(list1)
all_td2 = soup.find_all('td', {'align': 'center', 'valign': None})
list2 = []
for obj in all_td2:
list2.append(obj.contents[0])
new_list2 = []
for i in range(1, len(list2), 4):
if i >= 9:
#print(list2[i]) #9, 13, 17, 21
new_list2.append(list2[i].strip())
print(new_list2)
all_td3 = soup.find_all('td', {'align': 'right', 'valign': None})
list3 = []
for obj in all_td3:
list3.append(obj.contents[0].strip())
print(list3)
content = ''
for i in range(len(list1)):
content += str(list1[i]) + '\t' + str(new_list2[i])+ " 學分" + "\n成績:" + str(list3[i]) + '\n\n'
#print(content)
line_bot_api.reply_message(
event.reply_token,
TextSendMessage(text=content))