最近初学Python,想了解一下模拟登陆的流程,故根据网上查阅的一些资料,完成以下脚本,用于登陆北邮校园网网关 10.3.8.211。
#!/usr/bin/env python
# coding=utf-8
# 北邮网关登陆import urllib2
import urllib
import re
import osclass Loginer():def __init__(self, username, password):self.loginUrl = 'http://10.3.8.211/'self.username = usernameself.password = passwordself.openner = urllib2.build_opener()def login(self):postdata = {'DDDDD': self.username,'upass': self.password,'savePWD': 0,'0MKKey': ''}postdata = urllib.urlencode(postdata)myRequest = urllib2.Request(url=self.loginUrl, data=postdata)# myRequest.add_header('Referer','http://10.3.8.211/')# myRequest.add_header('User-Agent','Moz