为了反盗号,我没有给我的uid以及__cilent_id。
这是源代码(把LHQing的东西套了一下)
#By LHQing 2023.4.23
import requests
import random
import sys
tmpf=__file__
path=tmpf[:tmpf.rfind("\\")]
path=path+"\\"
code_fin=open(path+"Code.txt",mode="r")
code_=code_fin.readline().rstrip('\n')
code_fin.close()
cookie_fin=open(path+"Cookie.txt",mode="r")
tmp1=cookie_fin.readline().rstrip('\n').split(' ',1)
cookie_="__client_id="+tmp1[1]+"; _uid="+tmp1[0]
cookie_fin.close()
code_submit = """
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b;
}
"""
PostData={
"file": code_submit
}
user_agents=[
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",
"Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)",
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1 QQBrowser/6.9.11079.201"
]
url1="https://www.luogu.com.cn/user/"+tmp1[0]
ua_=random.choice(user_agents)
GetHeaders={
"Cookie": cookie_,
"Referer": "https://www.luogu.com.cn/",
"User-Agent": ua_
}
try:
response1=requests.get(url1,headers=GetHeaders,timeout=6)
except:
sys.exit()
rsp1=response1.text
tmp2=rsp1.split('\n')
token_=""
for tmp3 in tmp2:
tmp4=tmp3.split('"')
if len(tmp4)>=4:
if tmp4[1]=="csrf-token":
token_=tmp4[3]
break
url2="https://www.luogu.com.cn/fe/api/problem/submit/P1001"
PostHeaders={
"Cookie": cookie_,
"Referer": "https://www.luogu.com.cn/user/"+tmp1[0],
"User-Agent": ua_,
"X-CSRF-TOKEN": token_
}
try:
response2=requests.post(url2,json=PostData,headers=PostHeaders,timeout=6)
except:
sys.exit()
fout=open(path+"Return.txt",mode="w")
print(response2.content)
fout.close()
这是我的终端输出:
b'{"status":400,"data":"\\u4ee3\\u7801\\u8fc7\\u77ed","errorMessage":"\\u4ee3\\u7801\\u8fc7\\u77ed","trace":"","customData":[]}'