Created
October 2, 2017 14:43
-
-
Save hephyr/348610d78b148861810e5da78eabe083 to your computer and use it in GitHub Desktop.
济南大学联通网登录
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import re | |
import urlparse | |
import requests | |
def getURL(): | |
url = 'http://www.163.com' | |
r = requests.get(url) | |
result = re.findall('window.location.href="(.*?)"', r.text) | |
url = result[0] | |
print url | |
return url | |
def postForm(url, username, password, schoolid='510592'): | |
rs = urlparse.urlparse(url) | |
q = urlparse.parse_qs(rs.query) | |
login_url = 'http://'+rs.netloc+'/sdjd/protalAction!portalAuth.action' | |
headers = { | |
'host': rs.netloc, | |
'referer': 'http://'+rs.netloc+'/sdjd/protalAction!index.action?wlanuserip=10.177.25.222&basip=124.128.40.39', | |
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36', | |
'Cookie': 'JSESSIONID=28DFF62C185671AABE3757B1911A5A8B; lt=1; route=74f51685c56f1c432de12cf91a407795', | |
} | |
data = { | |
'wlanuserip': q['wlanuserip'], | |
'localIp': '', | |
'basip': q['basip'], | |
'lt': '1', | |
'lpsUserName': username, | |
'lpsPwd': password, | |
'schoolId': schoolid, | |
'rmbUser': 'on' | |
} | |
r = requests.post(login_url, headers=headers, data=data) | |
print r.text | |
if __name__ == '__main__': | |
url = getURL() | |
username = raw_input('账号:') | |
password = raw_input('密码:') | |
postForm(url, username, password) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment