2026年1月28日星期三

” Powerful Nation Forum Auto-Sign-In Script Guide ”

Summary: This script automates login and sign-in for the Powerful Nation Forum. It opens the forum page, detects login status, attempts login via text detection if needed, and performs sign-in via multiple fallback paths. Key features include screenshot captures for debugging, pop-up handling, and safe click functions. Setup involves server purchase (Alibaba Cloud, Tencent Cloud, Huawei Cloud) and deployment via Qinglong Panel. The script uses environment variables for credentials and is intended for testing and learning only.

1.购买服务器

阿里云:

服务器购买地址

https://t.aliyun.com/U/kcPAeY

若失效,可用地址

https://www.aliyun.com/daily-act/ecs/activity_selection?source=5176.29345612&userCode=49hts92d

腾讯云:

https://curl.qcloud.com/wJpWmSfU

若失效,可用地址

https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=ad201ee2ef3b771157f72ee5464b1fea&from=console

华为云

https://activity.huaweicloud.com/cps.html?fromacct=64b5cf7cc11b4840bb4ed2ea0b2f4468&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905

2.部署教程

2024年最新青龙面板跑脚本教程(一)持续更新中

3.代码如下

# -*- coding: utf-8 -*-
import osimport timeimport refrom datetime import datetimefrom pathlib import Path
from playwright.sync_api import sync_playwright, TimeoutError as PWTimeoutError
BASE_URL = "http://bbs1.people.com.cn/board/1.html"OUT_DIR = Path("qg_bbs_artifacts")OUT_DIR.mkdir(exist_ok=True)
# ---------------------------# 工具函数# ---------------------------
def now_str():    return datetime.now().strftime("%Y%m%d_%H%M%S")
def log(msg: str):    print(f"[{datetime.now().strftime('%H:%M:%S')}{msg}")
def shot(page, name: str):    fp = OUT_DIR / f"{now_str()}_{name}.png"    page.screenshot(path=str(fp), full_page=True)    log(f"📸 截图:{fp}")
def safe_click(locator, desc: str, timeout_ms: int = 5000) -> bool:    try:        locator.first.wait_for(state="visible", timeout=timeout_ms)        locator.first.click(timeout=timeout_ms)        log(f"✅ 点击:{desc}")        return True    except Exception as e:        log(f"⚠️ 点击失败:{desc} / {e}")        return False
def find_and_click_by_text(page, keywords, desc_prefix="按钮"):    """    在当前页面内,按文本关键字寻找可能的入口并点击    """    for kw in keywords:        # 常见:a、button、span/div role=button        candidates = [            page.locator(f"text={kw}"),            page.get_by_role("link", name=re.compile(kw)),            page.get_by_role("button", name=re.compile(kw)),        ]        for loc in candidates:            if safe_click(loc, f"{desc_prefix}"):                return True    return False
def try_close_popups(page):    """    关闭常见弹窗:知道了/关闭/我知道了/×    """    close_words = ["关闭""我知道了""知道了""取消""稍后""×""x"]    for w in close_words:        try:            loc = page.locator(f"text={w}")            if loc.count() > 0 and loc.first.is_visible():                loc.first.click(timeout=1500)                log(f"🧹 关闭弹窗:{w}")                time.sleep(0.5)        except Exception:            pass
# ---------------------------# 核心流程# ---------------------------
def open_home(page):    log(f"🌐 打开页面:{BASE_URL}")    page.goto(BASE_URL, wait_until="domcontentloaded", timeout=60000)    page.wait_for_timeout(1500)    try_close_popups(page)    shot(page, "home")
def is_logged_in(page) -> bool:    """    用"退出/注销/个人中心/我的"等关键字做弱判断(不同站点字段不同)    """    hints = ["退出""注销""个人中心""我的""消息""设置"]    for h in hints:        try:            if page.locator(f"text={h}").first.is_visible(timeout=800):                return True        except Exception:            pass    return False
def try_login(page, username: str, password: str) -> bool:    """    尝试进入登录页并完成登录(若站点为单点登录/第三方登录/验证码,可能需要手动补一刀)    """    log("🔐 尝试登录流程...")
    # 1) 先找"登录/账号登录/用户登录"    login_entry_words = ["登录""账号登录""用户登录""登录论坛""请登录"]    clicked = find_and_click_by_text(page, login_entry_words, "登录入口")    if clicked:        page.wait_for_timeout(1500)        try_close_popups(page)        shot(page, "after_click_login_entry")
    # 2) 找输入框:用户名/手机号/邮箱 + 密码    # 这里用比较宽泛的 selector,确保能匹配不同站点的input    user_selectors = [        "input[name='username']",        "input[name='user']",        "input[name='account']",        "input[type='text']",        "input[placeholder*='手机']",        "input[placeholder*='邮箱']",        "input[placeholder*='账号']",        "input[placeholder*='用户名']",    ]    pwd_selectors = [        "input[name='password']",        "input[type='password']",        "input[placeholder*='密码']",    ]
    user_filled = False    for sel in user_selectors:        loc = page.locator(sel)        if loc.count() > 0:            try:                loc.first.click(timeout=1500)                loc.first.fill(username, timeout=1500)                user_filled = True                log(f"✅ 已填写用户名(selector={sel})")                break            except Exception:                pass
    pwd_filled = False    for sel in pwd_selectors:        loc = page.locator(sel)        if loc.count() > 0:            try:                loc.first.click(timeout=1500)                loc.first.fill(password, timeout=1500)                pwd_filled = True                log(f"✅ 已填写密码(selector={sel})")                break            except Exception:                pass
    if not (user_filled and pwd_filled):        log("⚠️ 未能定位到用户名/密码输入框(可能是单点登录/验证码/iframe),需要你根据截图微调选择器")        shot(page, "login_inputs_not_found")        return False
    shot(page, "filled_credentials")
    # 3) 点击提交:登录/提交/确定    submit_words = ["登录""提交""确定""立即登录""确认"]    if not find_and_click_by_text(page, submit_words, "登录提交"):        log("⚠️ 未找到登录提交按钮")        shot(page, "login_submit_not_found")        return False
    # 4) 等待跳转/登录态出现    page.wait_for_timeout(4000)    try_close_popups(page)    shot(page, "after_login_submit")
    if is_logged_in(page):        log("🎉 登录态检测:已登录")        return True
    log("⚠️ 登录态检测:未确认登录成功(可能需要验证码/二次确认)")    return False
def try_checkin(page) -> bool:    log("🧾 开始签到...")
    # 路径A:直接找"签到/打卡"    if find_and_click_by_text(page, ["签到""打卡""每日签到""立即签到"], "签到入口"):        page.wait_for_timeout(2000)        try_close_popups(page)        shot(page, "after_checkin_click")        return True
    # 路径B:先进"任务/活动/福利/积分"    if find_and_click_by_text(page, ["任务""任务中心""福利""活动""积分""签到中心"], "任务入口"):        page.wait_for_timeout(2000)        try_close_popups(page)        shot(page, "task_center")        # 进入后再找签到按钮        if find_and_click_by_text(page, ["签到""立即签到""打卡"], "签到按钮"):            page.wait_for_timeout(1500)            shot(page, "after_checkin_in_task_center")            return True
    # 路径C:个人中心 -> 签到    if find_and_click_by_text(page, ["我的""个人中心""个人主页""用户中心"], "个人中心入口"):        page.wait_for_timeout(2000)        try_close_popups(page)        shot(page, "profile_center")        if find_and_click_by_text(page, ["签到""每日签到""打卡"], "签到按钮"):            page.wait_for_timeout(1500)            shot(page, "after_checkin_in_profile")            return True
    log("❌ 未找到可执行的签到入口(请根据截图定位签到按钮/接口)")    shot(page, "checkin_not_found")    return False
def run():    username = os.getenv("QG_BBS_USERNAME""").strip()    password = os.getenv("QG_BBS_PASSWORD""").strip()    headless = os.getenv("QG_BBS_HEADLESS""true").strip().lower() in ["true""1""yes""on"]
    if not username or not password:        raise RuntimeError("请先设置环境变量 QG_BBS_USERNAME / QG_BBS_PASSWORD")
    with sync_playwright() as p:        browser = p.chromium.launch(headless=headless)        context = browser.new_context()        page = context.new_page()
        try:            open_home(page)
            if not is_logged_in(page):                ok = try_login(page, username, password)                if not ok:                    log("⚠️ 登录未完成,后续签到可能失败(请查看 artifacts 截图)")
            # 回到首页再尝试签到(有些站点登录后会跳走)            open_home(page)
            ok = try_checkin(page)            if ok:                log("✅ 签到流程已执行)")            else:                log("❌ 签到流程未完成")
        except PWTimeoutError as e:            log(f"❌ 页面超时:{e}")            shot(page, "timeout")        except Exception as e:            log(f"❌ 运行异常:{e}")            shot(page, "exception")        finally:            context.close()            browser.close()

if __name__ == "__main__":    run()
解析
该脚本为强国论坛自动签到脚本,主要作用包括:
  • 自动打开强国论坛页面,尝试识别当前是否已登录。

  • 如未登录:自动寻找"登录入口",填写账号密码并提交。

  • 登录后自动签到:找"签到/打卡",通过"任务中心/个人中心"兜底路径签到。

  • 全程截图落地qg_bbs_artifacts/),便于你快速定位:登录页是否是 iframe、是否有验证码、签到按钮实际叫什么、入口在哪个菜单里。

主要方法

  • run → 脚本总入口:读取环境变量、启动浏览器、串起"打开页面→登录→签到→退出"完整流程。

  • open_home → 打开论坛首页并等待基础加载,顺便尝试关闭常见弹窗并截图。

  • is_logged_in → 用"退出/个人中心/我的"等文本做弱判断,推断当前是否处于登录态。

  • try_login → 自动登录:点击登录入口→定位账号/密码输入框→提交→判断是否成功,并在关键节点截图。

  • try_checkin → 自动签到:按优先级尝试三条路径(直接签到→任务中心→个人中心),每一步都截图。

  • find_and_click_by_text → 文本驱动的"找按钮并点击"通用能力(link/button/text 三类定位方式)。

  • safe_click → 安全点击封装:等待可见再点,失败不抛崩、只打日志。

  • try_close_popups → 关闭常见弹窗("关闭/知道了/取消/×"等),减少干扰。

  • shot → 保存截图到本地目录,便于排障与后续精确改选择器。


注意

本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。


历史脚本txt文件获取>>
服务器搭建,人工服务咨询>>

没有评论:

发表评论

对标高手:从同行朋友圈“偷师”的赚钱捷径

内容:通过付费进入同行社群,潜伏观察其朋友圈文案、成交话术及运营节奏,吸收已验证的赚钱模型。分析不同阶段同行的策略,结合自身产品改良运用,避免闭门造车,以高效学习加速赚钱。 创业前3年,我赚的每一分钱,几乎都是从同行那里"偷"来的。 不是偷钱,是偷方法、偷...