好友
阅读权限10
听众
最后登录1970-1-1
|
25吾爱币
本帖最后由 87901434 于 2024-2-23 13:22 编辑
自己从biuli上看了视频,自己然后研究一个网站的签到。
已经提取出了formhash和loginhash,但是在最后一步签到的时候出现了问题
问题一:登录后提取的cookie与在签到的时候请求cookie有一部分不同,同时签到(def qiandao)里面有一个url2,里面有0.5575897161048038这个是不是时间?
问题二:签到不成功,
目前停在了def qiandao
还请各位指点一二。
[Python] 纯文本查看 复制代码 import requests,re
from bs4 import BeautifulSoup
s = requests.session()
url_hash = "https://www.4ksj.com/qiandao.php"
fromhash=""
loginhash=""
def get_fromhash():
url_fromhash = "https://www.4ksj.com/qiandao.php"
head = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.160 Safari/537.36",
"Referer": "https://www.4ksj.com/qiandao.php",
}
html = requests.get(url_fromhash,headers=head).text
soup = BeautifulSoup(html, "html.parser") # 格式化
all_titles = soup.find_all("a", attrs={"class": "btna"}) # <a href="qiandao.php?sign=6a55efc7" class="btna">点击打卡</a>
formbashtext = re.findall("sign=(.*?)\"", str(all_titles)) # 正则查找 print(len(formbashtext[0]))
#print("get_fromhash:", formbashtext)
if len(formbashtext[0]) == 8:
#print("get_fromhash:","fromhash获取成功:",formbashtext)
return formbashtext[0]
def get_loginhash(text):
url= "https://www.4ksj.com/member.php?mod=logging&action=login&infloat=yes&frommessage&inajax=1&ajaxtarget=messagelogin"
url_loginhash = "https://www.4ksj.com/qiandao.php?sign="+str(fromhash)
#print("url_loginhash:",url_loginhash)
login_cookie = None
head = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.160 Safari/537.36",
"Referer": "https://www.4ksj.com/qiandao.php",
"authority": "www.4ksj.com",
"method": "GET",
"path": "/qiandao.php?sign=" + loginhash,
"scheme": "https",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9",
#"Cache-Control": "max-age=0",
#"Content-Length": "140",
#"Content-Type": "application/x-www-form-urlencoded"
"cookie":None
}
###<input type="text" placeholder="用户名/UID/Email" name="username" id="username_Lm63Z" autocomplete="off" size="30" class="log-input" tabindex="1" value="">
html = requests.get(url,headers=head).text
soup = BeautifulSoup(html, "html.parser") # 格式化
loginbashtext = re.findall("main_messaqge_(.*?)\">", str(soup)) # 正则查找 print(len(formbashtext[0]))
# print("get_loginhash:", loginbashtext,len(loginbashtext[0]))
if len(loginbashtext[0]) == 5:
#print("loginbashtext:","loginbashtext获取成功:",loginbashtext[0])
return loginbashtext[0]
def login(username,password):
url=f"https://www.4ksj.com/member.php?mod=logging&action=login&loginsubmit=yes&frommessage&loginhash={loginhash}&inajax=1"
print(url)
head = {
"authority": "www.4ksj.com",
"path":"/member.php?mod=logging&action=login&loginsubmit=yes&frommessage&loginhash="+loginhash+"&inajax=1",
"scheme": "https",
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language":"zh-CN,zh;q=0.9",
"Cache-Control": "max-age=0",
"Content-Type": "application/x-www-form-urlencoded",
"Origin":"https://www.4ksj.com",
"referer": "https://www.4ksj.com/qiandao.php?sign="+fromhash,
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.160 Safari/537.36"
}
data = {
"formhash":fromhash,
"referer": "https://www.4ksj.com/qiandao.php?sign="+fromhash,
"username": username,
"password": password,
"questionid": 0,
"answer":"",
}
rescookie = s.post(url,headers=head,data=data).cookies #提取cookie
#print("cookie成功",rescookie)
cookie = requests.utils.dict_from_cookiejar(rescookie) #cookie格式化
#print("格式化cookie成功",cookie)
qiandao(cookie,rescookie)
def qiandao(cookie,rescookie):
url1="https://www.4ksj.com/qiandao.php"
url2="https://www.4ksj.com/misc.php?mod=patch&action=ipnotice&_r=0.5575897161048038&inajax=1&ajaxtarget=ip_notice"
head1 = {
"authority": "www.4ksj.com",
"path":"/qiandao.php",
"scheme": "https",
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language":"zh-CN,zh;q=0.9",
"referer": "https://www.4ksj.com/qiandao.php?sign="+fromhash,
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.160 Safari/537.36",
"cookies" : None
}
head2 = {
"authority": "www.4ksj.com",
"path":"/misc.php?mod=patch&action=ipnotice&_r=0.5575897161048038&inajax=1&ajaxtarget=ip_notice",
"scheme": "https",
"Accept":"*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language":"zh-CN,zh;q=0.9",
"referer": "https://www.4ksj.com/qiandao.php?sign="+fromhash,
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.160 Safari/537.36",
"cookies": None
}
head1["cookie"]=cookie
head2["cookie"]=cookie
print(head1["cookie"])
print(head2["cookie"])
##问题在这里
#res2 = s.get(url2, headers=head2)
#res1 = s.get(url1, headers=head1)
#print(res2)
#print(res2.text)
#print(res1)
#print(res1.text)
fromhash = get_fromhash()
loginhash = get_loginhash(fromhash)
print(fromhash,loginhash)
if len(fromhash) == 8 and len(loginhash) == 5 :
print("重要参数获取成功,开始登录:")
login("username","password") |
最佳答案
查看完整内容
你可以换一种思路,用登陆接口和签到接口传参,完成签到。
login_url="https://www.4ksj.com/member.php"
params = {
'mod': 'logging',
'action': 'login',
'loginsubmit': 'yes',
'handlekey': 'login',
'loginhash': 'LTy35',
'inajax': '1',
}
data = {
'formhash': '388c7862',
'referer': 'https://www.4ksj.com/qiandao.php?sign=b69be07a',
'username': 'your_user',
...
|