吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3421|回复: 21
收起左侧

[Python 转载] 搞了个精易论坛自动任务的代码

[复制链接]
tsu.xxw 发表于 2022-3-16 12:38
本帖最后由 tsu.xxw 于 2022-3-17 15:13 编辑

首先感谢论坛里朋友们的帮助,解决掉了我前两天的问题

改了下,解决了部分评分报错的问题
这两天无聊,试了试用python写了个精易论坛每天自动签到,评论,评分的代码

没什么大的用处,就是可以获得精币,嫖一些源码模块,所以勿喷

可以放进云函数,每天自动运行

如果要放在云函数自动执行,需要将以下代码

[Python] 纯文本查看 复制代码
if __name__ == "__main__":
    cookies='换cookies'
    page_number = random.randint(0, 40)
    test_cookie()


更换成

[Python] 纯文本查看 复制代码
def main_handler(*args):  # 腾讯云函数
    main()

def main():
    cookies = '换cookies'
    page_number = random.randint(0, 40)
    test_cookie()

if __name__ == '__main__':
    main()



效果图
11111.jpg

代码如下,换成自己cookies即可

[Python] 纯文本查看 复制代码
import requests
import random
from lxml import etree
import time
import re

def test_cookie():
    global cookies
    url="https://bbs.125.la/plugin.php?id=dsu_paulsign:sign"
    headers = {
        'cookie':cookies,
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62'
    }
    session= requests.session()
    rep=session.get(url=url,headers=headers)
    if rep.status_code == 200:
        print("登录成功")
        checkin()
        comment()
        time.sleep(7)
        score()
        ime.sleep(8)
        print('休息中')
    else:
        print("异常了,快看看")

def comment():
    text="""
        Host: bbs.125.la
        Connection: keep-alive
        Content-Length: 81
        Cache-Control: max-age=0
        sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Microsoft Edge";v="99"
        sec-ch-ua-mobile: ?0
        sec-ch-ua-platform: "Windows"
        Upgrade-Insecure-Requests: 1
        Origin: https://bbs.125.la
        Content-Type: application/x-www-form-urlencoded
        User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.39
        Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
        Sec-Fetch-Site: same-origin
        Sec-Fetch-Mode: navigate
        Sec-Fetch-User: ?1
        Sec-Fetch-Dest: iframe
        Referer: https://bbs.125.la/thread-14721307-1-1.html
        Accept-Encoding: gzip, deflate, br
        Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
        Cookie:换cookies
        """
    dic = get_canshu()
    tid = dic['tid']
    formhash = dic['formhash']
    url='https://bbs.125.la/forum.php?mod=post&action=reply&fid=98&tid='+tid+'&fromvf=1&extra=page=1&replysubmit=yes&infloat=yes&handlekey=vfastpost&inajax=1'
    headers=trans_headers2(text)
    data='formhash='+formhash+'&message=+%E9%A1%B6%EF%BC%8C%E5%AD%A6%E4%B9%A0%E4%B8%80%E4%B8%8B'
    session = requests.session()
    rep = session.post(url=url, headers=headers,data=data)
    print(rep.text)



def trans_headers2(text):         #格式化请求头
    headers = text
    headers = headers.strip().split('\n')
    headers = {x.split(':')[0].strip(): ("".join(x.split(':')[1:])).strip().replace('//', "://") for x in headers}
    return headers

def get_canshu():        #获取formhash , tid , pid,以字典返回
    global page_number
    url='https://bbs.125.la/thread-'+ get_page()[page_number] +'-1-1.html'
    print(get_page()[page_number])
    text='''
    accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
    accept-encoding: gzip, deflate, br
    accept-language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
    cache-control: max-age=0
    cookie:换cookies
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Microsoft Edge";v="99"
    sec-ch-ua-mobile: ?0
    sec-ch-ua-platform: "Windows"
    sec-fetch-dest: document
    sec-fetch-mode: navigate
    sec-fetch-site: cross-site
    sec-fetch-user: ?1
    upgrade-insecure-requests: 1
    user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.39
    '''
    headers=trans_headers2(text)
    rep=requests.get(url=url,headers=headers).text
    # pattern=re.compile(r'formhash=(.*?)\"')
    formhash_init=re.search(r'formhash=(?P<formhash>.*?)"',rep)
    pid_init = re.search(r'pid(?P<pid>.*?)"', rep)

    cansu={}
    cansu['formhash'] = formhash_init.group("formhash")
    cansu['tid'] = get_page()[page_number]
    cansu['pid'] = pid_init.group("pid")
    print(cansu)
    return cansu




def score():         #进行每日评分,注意,每日4分
    global cookies
    try:
        headers = {
            'cookie': cookies,
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62'
        }
        session = requests.session()
        dic = get_canshu()
        tid = dic['tid']
        pid = dic['pid']
        formhash = dic['formhash']
        url_page = 'https://bbs.125.la/thread-' + tid + '-1-1.html'
        rep = session.get(url=url_page, headers=headers)
        print(url_page)
        print("获取pid={}与tid={}与formash={}成功,开始自动评分".format(pid, tid, formhash))
        # 开始评分
        url_score = 'https://bbs.125.la/forum.php?mod=misc&action=rate&ratesubmit=yes&infloat=yes&inajax=1'
        data = 'formhash=' + formhash + '&tid=' + tid + '&pid=' + pid + '&referer=https%3A%2F%2Fbbs.125.la%2Fforum.php%3Fmod%3Dviewthread%26tid%3D' + tid + '%26page%3D0%23pid' + pid + '&handlekey=rate&score4=%2B1&reason=%E6%84%9F%E8%B0%A2%E5%88%86%E4%BA%AB%EF%BC%8C%E5%BE%88%E7%BB%99%E5%8A%9B%EF%BC%81%7E'
        headers['Content-Type'] = 'application/x-www-form-urlencoded'
        headers['Referer'] = 'https://bbs.125.la/thread-'+tid+'-1-1.html'
        rep_score = session.post(url=url_score, data=data, headers=headers)
        print(rep_score.text)
    except:
        print('不存在帖子')

#获取易语言源码模块的第二页帖子
def get_page():
    text='''
    accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
    accept-encoding: gzip, deflate, br
    accept-language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
    cache-control: max-age=0
    cookie: 换cookies
referer: https://bbs.125.la/
    sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Microsoft Edge";v="99"
    sec-ch-ua-mobile: ?0
    sec-ch-ua-platform: "Windows"
    sec-fetch-dest: document
    sec-fetch-mode: navigate
    sec-fetch-site: same-origin
    sec-fetch-user: ?1
    upgrade-insecure-requests: 1
    user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.39
    '''
    headers=trans_headers2(text)
    url='https://bbs.125.la/forum-98-2.html'
    session = requests.session()
    rep=session.get(url=url,headers=headers)
    tree=etree.HTML(rep.text)
    tbody_list=tree.xpath('/html/body/div[7]/div[5]/div/div/div[5]/div[2]/form/table/tbody')
    id_list=[]
    for tbody in tbody_list:
        id_list.append(tbody.xpath('@id'))
    del id_list[0]
    id=[]
    for i in range(len(id_list)):
        id.append(id_list[i-1][0])
    for i in range(len(id)):
        id[i-1]=id[i-1].split('_')[1]
    return id





def checkin():    #签到
    global cookies
    url="https://bbs.125.la/plugin.php?id=dsu_paulsign:sign&operation=qiandao&infloat=1"
    data={
        "formhash": "8b9834f2",
        "submit": "1",
        "targerurl":"",
        "todaysay":"",
        "qdxq": "kx"
    }
    headers = {
        'cookie': cookies,
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62'
    }
    session=requests.session()
    rep=session.post(url=url,headers=headers,data=data)
    jso=rep.json()
    print(jso)




if __name__ == "__main__":
    cookies='换cookies'
for i in range(15):
    page_number = random.randint(0, 40)
        print(page_number)
        test_cookie()

#腾讯云函数用这个
# def main_handler(*args):  # 腾讯云函数
#     main()
#
# def main():
#     cookies = '换cookies'
#     page_number = random.randint(0, 40)
#     test_cookie()
#
# if __name__ == '__main__':
#     main()






免费评分

参与人数 2吾爱币 +3 热心值 +2 收起 理由
ncu.xxy + 1 + 1 谢谢@Thanks!
Ls30 + 2 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

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

Prozacs 发表于 2022-3-17 15:53
Cloudflare 5秒盾、用cloudscraper请求。
session = requests.session()
session = cloudscraper.create_scraper(session)
content = session.get('').text
 楼主| tsu.xxw 发表于 2022-3-16 15:29
13729181580 发表于 2022-3-16 12:39
Ls30 发表于 2022-3-16 12:52
感谢分享,明天再去试试
wenz 发表于 2022-3-16 12:59
谢谢老哥分享
wfys66 发表于 2022-3-16 13:06

感谢分享
icode_isky 发表于 2022-3-16 13:09
感谢分享!
o824 发表于 2022-3-16 13:15
感谢分享
xcy1253 发表于 2022-3-16 13:29
可惜不会用
gentry2008 发表于 2022-3-16 13:40
谢谢分享,向楼主致敬
MinChaoRouji 发表于 2022-3-16 13:46
感谢分享 谢谢
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

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

GMT+8, 2024-11-29 00:40

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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