Skip to content

Instantly share code, notes, and snippets.

@yuantailing
Last active August 31, 2021 22:45
Show Gist options
  • Save yuantailing/85f5e4798d6523472ef102f59b55f715 to your computer and use it in GitHub Desktop.
Save yuantailing/85f5e4798d6523472ef102f59b55f715 to your computer and use it in GitHub Desktop.
Hi freshmen, find your student number in Tsinghua.
import http.cookiejar
import urllib.parse
import urllib.request
# Run the script with Python3.
# Please use your own information, and don't be evil.
name = '张三'
id = '110101199901234567'
number_start = 2019310001
# Use 2019310001 if you are PhD student.
# Change it to 2019210001 if you are master student.
if __name__ == '__main__':
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
url_base = 'https://id.tsinghua.edu.cn/'
opener.open(url_base + r'do/off/ui/activation')
for number in range(number_start, number_start + 4000):
r = opener.open(
url_base + r'do/off/ui/activation/grad/pre-register/conform',
r'realName={}&idNo={}&userId={}'.format(
urllib.parse.quote(name.encode('gbk')),
id,
number,
).encode(),
)
assert 200 == r.code
if '/do/off/ui/activation/grad/pre-register/error' in r.url:
print(number, 'incorrect')
else:
print('Your student number is', number)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment