A small program that simulates logging into the academic administration system to calculate GPA

零下一度
Release: 2017-05-27 14:43:54
Original
4232 people have browsed it

After making some small games, I began to slowly realize that typing code is a physical job, and you can get through it slowly. In the past few days, I have had the urge to write a small program that simulates logging into the academic administration system to calculate GPA. However, I didn’t have any experience in network programming before, so I took advantage of the four-day holiday after the midterm exam to fill in the gaps bit by bit. Recently I have an inexplicable fondness for the Java language. I originally planned to use Java for development, but it turns out that Java seems to be more troublesome than python
in terms of network programming. In addition, one method of Java was used incorrectly, which caused the school's academic administration system to mistakenly think that I was performing SQL injection and blocked my IP. (...) From then on, I made up my mind to write in python.  

cookie

is used to record the session status after login.
# 保存cookie
cj = cookielib.LWPCookieJar()
cookie_support = urllib2.HTTPCookieProcessor(cj)
opener = urllib2.build_opener(cookie_support, urllib2.HTTPHandler)
urllib2.install_opener(opener)
Copy after login
First use a browser to log in to the educational system, open the console, analyze what messages need to be posted on the login webpage and find out the real requested webpage.

A small program that simulates logging into the academic administration system to calculate GPA
A small program that simulates logging into the academic administration system to calculate GPA From the analysis of the above two pictures, we can get the real requested web page: 121.251.19.29/pass.asp

Login requires post The data is: UserStyle, user, password, where UserStyle is the radio type. Looking at the source code of the web page, it can be divided into three types: student, teacher and OtherUser.

Next, send a post request.

url = '121.251.19.29/pass.asp'
h = urllib2.urlopen(url)
info = {'UserStyle': 'student', 'user': user, 'password': psw}
info = urllib.urlencode(info)
req = urllib2.Request(url, info)
urllib2.urlopen(req)
Copy after login

After successfully logging in, click on the option to find the score query and find the requested web page: 121.251.19.29/student/asp/Select_Success.asp

A small program that simulates logging into the academic administration system to calculate GPA Open the request webpage and read the source code of the score page

req = urllib2.Request('121.251.19.29/student/asp/Select_Success.asp')
resData = urllib2.urlopen(req)
res = resData.read()  # 读取成绩页面
Copy after login

Use regular expressions to filter all HTML tags. The remaining content is parsed. The table displaying the scores has a periodic pattern, extract the scores and credits of the corresponding subjects, and finally calculate the average score and grade points.

tag = re.compile(&#39;</?[^>]*>&#39;)
s = re.sub(tag, &#39;&#39;, res)  # 过滤标签
tmp = s.split()
Copy after login

Of course, if the account or password is entered incorrectly, the login request will fail and the user will be prompted to re-enter the account and password. Below I found several classmates’ accounts to test.

A small program that simulates logging into the academic administration system to calculate GPA
A small program that simulates logging into the academic administration system to calculate GPA
A small program that simulates logging into the academic administration system to calculate GPA
A small program that simulates logging into the academic administration system to calculate GPA Finally, I was a little clever. After the account is successfully logged in, the account password will be sent to My email

I won’t write the content of python’s simulation of sending ordinary text emails. . Just open source: github.com/ly941122/CalGPA

[Related recommendations]

1.

PHP collection and simulated login forum applet_PHP tutorial

2.

Instructions for creating the login process for WeChat mini program development

3.

Form verification example tutorial for mini program development

4. Details

Solution and Optimization of Your WeChat Mini Program

The above is the detailed content of A small program that simulates logging into the academic administration system to calculate GPA. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template