参考知乎链接:https://zhuanlan.zhihu.com/p/140372568
环境:python3.7
请求头,请求地址都可以在开发者模式的网络中抓取,此处需要登录到USVN才能获取到cookie
import requests
import time
headers={
"Host":"svn.xurikeji.net:8088",
"Referer":"http://svn.xurikeji.net:8088/admin/group/new",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0",
"Content-Type":"application/x-www-form-urlencoded",
"Cookie":"experimentation_subject_id=IjBiNDgxZTMz83jf93h923hdijnogj38ehf29jY2NkMzFkZTI5YiI%3D--29bff0b0d99u21ih891dhisahfn81hr9osij21; PHPSESSID=r0u3b49iud3233ge28h8efi3jhedfiu4u"
}
#response=requests.get(url,headers=headers,cookies=cookie_dict)
#print(response)
#文件夹中的地址是用 \ 来分隔不同文件夹的,而Python识别地址时只能识别用 / 分隔的地址。
with open(r'D:\xurikeke.hi\桌面\group.txt','r+') as file:
for line in file:
payload={"groups_name":line.strip("\n"),"groups_description":"","submit":"提交"}
#这里用data是因为"Content-Type":"application/x-www-form-urlencoded",具体看上面的参考链接
response=requests.post("http://svn.xurikeji.net:8088/admin/group/create",data=payload,headers=headers)
print("%s 用户组已被成功添加!" % line.strip("\n"))
print("============================================================================================")
time.sleep(3)
print("所有用户组添加完成!")