forked from weirenxue/ithelp-login-script
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (34 loc) · 1.42 KB
/
main.py
File metadata and controls
40 lines (34 loc) · 1.42 KB
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
import os
from datetime import datetime
import requests
from bs4 import BeautifulSoup as bs
try:
account = os.getenv("ITHELP_ACCOUNT")
password = os.getenv("ITHELP_PASSWORD")
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
}
loginPayload = {
"account": account,
"password": password,
"_token": "",
}
sess = requests.Session()
sess.headers.update(headers)
url = "https://member.ithome.com.tw/login"
response = sess.get(url)
bsObj = bs(response.text, "html.parser")
loginToken = bsObj.find("input", {"name": "_token"}).attrs["value"]
loginPayload["_token"] = loginToken
url = "https://member.ithome.com.tw/login"
response = sess.post(url, data=loginPayload)
bsObj = bs(response.text, "html.parser")
account = bsObj.find("p", {"class": "account-fontsize"}).get_text()
if account == loginPayload["account"]:
url = "https://member.ithome.com.tw/oauth/authorize?client_id=ithelp&redirect_uri=https://ithelp.ithome.com.tw/users/callback&response_type=code"
response = sess.get(url)
print(datetime.now().strftime("%Y/%m/%d %H:%M:%S"), "Login Successful.")
url = "https://lwsu-linebot.herokuapp.com/"
response = sess.get(url)
except Exception as e:
print(datetime.now().strftime("%Y/%m/%d %H:%M:%S"), "Login Failed.")