python 爬课表
import requests
from bs4 import BeautifulSoup
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware
app = FastAPI()
origins = [
"*"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=[""],
allow_headers=[""],
)
@app.get("/")
async def root(username: int , password: int ,week: int ):
login_url = 'https://app.upc.edu.cn/uc/wap/login/check'
login_data = {'username': username, 'password': password}
# re = requests.post(login_url, data)
# re.encoding = re.apparent_encoding
# soup = BeautifulSoup(re.text,'html.parser')
# cookie = re.cookies
res = requests.post(login_url, login_data)
cookies = requests.utils.dict_from_cookiejar(res.cookies)
print(cookies)
schedule_url = '############################'
schedule_data = {'year': '2019-2020', 'term': 2, 'week': week, 'type': 2}
res_sc = requests.post(schedule_url, data=schedule_data, cookies=cookies)
res_sc.encoding = res_sc.apparent_encoding
return res_sc.json()
posted on 2020-02-21 10:53 chenchang12 阅读(193) 评论(0) 编辑 收藏 举报