我想做一个SIGAA UnB的邮寄方法,相当于" Select 一个部门,年份,毕业和按Search".
我使用Mozilla Web Inspector查看了引用的POST请求的详细信息.复制它的头部和正文,提取ID和Cookie会话,并将HTML响应导出到文件中.每次我try 这样做时,我只得到标准页面,就好像POST方法不起作用一样.有人能解释一下这里遗漏了什么吗?
from bs4 import BeautifulSoup as BS4
import requests
page = requests.Session()
# GET Method to search for Cookies and IDs
answer = page.get("https://sigaa.unb.br/sigaa/public/turmas/listar.jsf?aba=p-ensino")
my_cookie = answer.cookies
j_id = BS4(answer.text, "html.parser").find(id="javax.faces.ViewState")["value"]
post_header = {
"Host": "sigaa.unb.br",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
"Accept-Language": "pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3",
"Accept-Encoding": "gzip, deflate, br",
"Content-Type": "application/x-www-form-urlencoded",
"Content-Length": "194",
"Origin": "https://sigaa.unb.br",
"Connection": "keep-alive",
"Referer": "https://sigaa.unb.br/sigaa/public/turmas/listar.jsf?aba=p-ensino",
"Cookie": str(my_cookie["JSESSIONID"]),
"Upgrade-Insecure-Requests": "1",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?1",
}
post_form = {
"formTurma": "formTurma",
"formTurma:inputNivel" : "G",
"formTurma:inputDepto" : "673",
"formTurma:inputAno" : "2023",
"formTurma:inputPeriodo" : "1",
"formTurma:j_id_jsp_1370969402_11" : "Buscar",
"javax.faces.ViewState": str(j_id),
}
answer = page.post("https://sigaa.unb.br/sigaa/public/turmas/listar.jsf?aba=p-ensino", data=post_form, headers=post_header, cookies=my_cookie)
profile_file = open("sigaa.html", "w")
profile_file.write(answer.text)