杭电研究生自动登录联网脚本

简介

对于网页端口的python登录

code

'''
@Description: 
@Author: shaonianruntu
@Github: https://github.com/shaonianruntu
@Date: 2020-05-06 17:28:50
LastEditTime: 2021-01-09 21:54:41
'''
import urllib.parse
import urllib.request

url = "http://2.2.2.2"

username = ""  # add ihdu student id
pwd = ""  # add ihdu passwd

headers = {"Host": "2.2.2.2", "User-Agent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0",
 "Accept-Language": "en-US,en;q=0.5",
 "Accept-Encoding": "gzip, deflate",
 "Content-type":"application/x-www-form-urlencoded; charset=UTF-8",
 "Accept":"*/*",
 "Referer":"http://2.2.2.2/ac_portal/default/pc.html?tabs=pwd",
 "X-Requested-With":"XMLHttpRequest",
 "connection":"keep-alive"}
data = {
    "opr": "pwdLogin",
    "userName": username,
    "pwd": pwd,
    "rememberPwd": "1"
}

url = "http://2.2.2.2/ac_portal/login.php"

data = urllib.parse.urlencode(data).encode("utf-8")

req = urllib.request.Request(url, data, headers)

with urllib.request.urlopen(req) as f:
    resp = f.read()
    print(resp)
原文地址:https://www.cnblogs.com/eat-too-much/p/14259351.html