# -*- coding: UTF-8 -*-
# !/usr/bin/env python3
# Author:  Murphy

import re
import requests


class FishCSign(object):
    def __init__(self):
        self.session = requests.Session()
        self.username = "Your username"
        self.password = "Your encryption password"
        self.home_url = "https://fishc.com.cn/forum.php"
        self.login_url = "https://fishc.com.cn/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1"
        self.headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36"}

    def log_in(self):
        login_data = {
            "username": self.username,
            "password": self.password,
            "quickforward": "yes",
            "handlekey": "1s"
        }

        login_response = self.session.post(self.login_url, data=login_data, headers=self.headers)
        login_result = re.search(r'<root><!\[CDATA\[(.*)<script type="text/javascript".+</script>\]\]></root>', login_response.text).group(1)
        if login_result == "":
            print("Login successful.")
            return True
        else:
            print(login_result)
            return False

    def get_formhash(self):
        response = self.session.get(self.home_url, headers=self.headers)
        try:
            formhash = re.search(r'<input type="hidden" name="formhash" value="(.+)" />', response.text).group(1)
            return formhash
        except AttributeError:
            raise ValueError("Get formhash Failed")

    def sign(self):
        login_status = self.log_in()
        if login_status:
            formhash = self.get_formhash()
            sign_url = f"https://fishc.com.cn/plugin.php?id=k_misign:sign&operation=qiandao&formhash={formhash}&format=empty&inajax=1&ajaxtarget=JD_sign"
            sign_response = self.session.get(sign_url, headers=self.headers)
            sign_result = re.search(r"<root><!\[CDATA\[(.*)\]\]></root>", sign_response.text).group(1)

            if sign_result == "" or sign_result == "今日已签":
                print("Sign successful.")
            else:
                print(sign_result)


if __name__ == "__main__":
    fish = FishCSign()
    fish.sign()
Last modification:April 14, 2020
如果觉得我的文章对你有用,请随意赞赏