python爬虫获取强智科技教务系统学科成绩(模拟登录+成绩获取)

版权声明:版权所有,尊重原创。转载请注明出处: https://blog.csdn.net/qq_36426650/article/details/77849872
直接贴出代码提供分享
欢迎访问实例(本作者自己写的网站):www.wjn1996.cn/estudy,进入首页往下点击“常用工具》教务成绩查询”,网站采用jsp调用python脚本,具体疑问可提出。


 
 
import urllib
import urllib.request
import urllib.parse
import http.cookiejar
PostUrl = "http://jwgl.just.edu.cn:8080/jsxsd/xk/LoginToXk"
cookie =  http.cookiejar.CookieJar()
hander = urllib.request.HTTPCookieProcessor(cookie)
opener = urllib.request.build_opener(hander)
headers ={
    'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Connection':'keep-alive',
    'Accept-Language':'zh-CN,zh;q=0.8',
    'Content-Type':'application/x-www-form-urlencoded',
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
}
PostData = {
    'USERNAME':'******',#'这里填写学号
    'PASSWORD':'******'#这里填写密码
}
data = urllib.parse.urlencode(PostData).encode(encoding = 'utf-8')
request = urllib.request.Request(PostUrl,data,headers)
response = opener.open(request)
result = response.read().decode('utf-8')
#print(result)
res = opener.open('http://jwgl.just.edu.cn:8080/jsxsd/kscj/cjcx_list')
#print(res.read().decode('utf-8'))
from bs4 import BeautifulSoup
html_text = BeautifulSoup(res.read().decode('utf-8'),'html.parser')
td = html_text.select('td')
all_test_list = []
list = []
for i in td:    
    if i.text != '':
        list.append(i.text)
    else:
        if len(list)>0:
            all_test_list.append(list)
            list = []
        continue
    #print (i.text)
#print(all_test_list)
for i in all_test_list:
    print(i)#这里输出每一个课程的成绩list
 #   print(i[3] , i[4])

猜你喜欢

转载自blog.csdn.net/qq_36426650/article/details/77849872