通過python的requests模塊實現的一鍵登錄、註銷、查看校園網
# -*- coding: utf-8 -*-
import requests
import re
session=requests.session()
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 UBrowser/5.5.10106.5 Safari/537.36',
'Referer' : 'http://10.3.8.211/F.htm',
'Connection':'keep-alive',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding':'gzip, deflate'}
cookies={
'myusername':'*****',#username
'username':'******',#username
'smartdot':'*****'#passwd
}
postData={
'DDDDD':'*******',#username
'upass':'******',#passwd
'0MKKey':''
}
url='http://10.3.8.211'
detectx=session.get('http://10.3.8.211/')
detectx.encoding='GB2312'
result1=detectx.text
if re.findall('上網註銷窗',result1):
flow=(re.findall("flow='(.*?)'",result1))[0]
flow=((float)(flow.strip()))/1024
fee=(re.findall("fee='(.*?)'",result1))[0]
fee=(float(fee.strip()))/10000
print('已登陸\n流量使用: '+str(flow)+'MB\n剩餘餘額 :'+str(fee)+'元')
#str=raw_input('是否註銷?')
str=input('是否註銷?')
if str=='yes':
session.get('http://10.3.8.211/F.htm')
print('註銷成功')
else :
startLogin=session.post(url,data=postData)
startLogin.encoding='GB2312'
detectx=session.get(url)
detectx.encoding='GB2312'
result1=detectx.text
flow=(re.findall("flow='(.*?)'",result1))[0]
flow=((float)(flow.strip()))/1024
fee=(re.findall("fee='(.*?)'",result1))[0]
fee=(float(fee.strip()))/10000
print('登陸成功\n流量使用: '+str(flow)+'MB\n剩餘餘額 :'+str(fee)+'元')
#str=raw_input('是否註銷?')
str=input('是否註銷?')
if str=='yes':
session.get('http://10.3.8.211/F.htm')
print('註銷成功')
運行成功之後可以通過pyinstaller將py轉換win平臺可用exe文件。