吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 492|回复: 4
收起左侧

[经验求助] python签到制作失败

[复制链接]
87901434 发表于 2024-2-23 13:19
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', ...

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

china1937 发表于 2024-2-23 13:19
你可以换一种思路,用登陆接口和签到接口传参,完成签到。
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',
    'password': 'your_pwd',
    'questionid': '0',
    'answer': '',
}
post请求从返回的值里面提取sign的值,
签到接口:url="https://www.4ksj.com/qiandao.php"
sign_value= "上面提取的sign的值"
params = { 'sign': sign_value, }
再做get请求就可以了
大致思路是这样的
china1937 发表于 2024-2-23 14:38
china1937 发表于 2024-2-23 15:33
china1937 发表于 2024-2-23 15:28
你可以换一种思路,用登陆接口和签到接口传参,完成签到。
login_url="https://www.4ksj.com/member.php"
...

好像有点问题
额微粒波地 发表于 2024-2-23 16:25
最简单的方法,在电脑上操作签到前,浏览器打开f12-网络-保留日志-点击签到-点击该请求信息-右键复制curl(bash)-百度curl转换-直接转换成python语言!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-12-12 14:38

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表