76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
"""Probe gongzicp search and chapter content."""
|
|||
|
|
import base64
|
||
|
|
import json
|
||
|
|
import re
|
||
|
|
import requests
|
||
|
|
from Crypto.Cipher import AES
|
||
|
|
from Crypto.Util.Padding import unpad
|
||
|
|
|
||
|
|
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0"
|
||
|
|
BASE = "https://www.gongzicp.com"
|
||
|
|
WEBAPI = BASE + "/webapi"
|
||
|
|
|
||
|
|
def js_to_string(n: int, base: int) -> str:
|
||
|
|
digits = "0123456789abcdefghijklmnopqrstuvwxyz"
|
||
|
|
s = ""
|
||
|
|
while n:
|
||
|
|
s = digits[n % base] + s
|
||
|
|
n //= base
|
||
|
|
return s or "0"
|
||
|
|
|
||
|
|
|
||
|
|
def make_aes():
|
||
|
|
e = "iGzsYn" + js_to_string(int("165455", 14), 32)
|
||
|
|
iv_str = "$h$b3!" + e
|
||
|
|
t = base64.b64decode("dTBMUnJidSRFbg==").decode()
|
||
|
|
key_str = t + js_to_string(int("4d5a6c8", 14), 36) + "A"
|
||
|
|
return key_str.encode("utf-8"), iv_str.encode("utf-8")
|
||
|
|
|
||
|
|
|
||
|
|
def decrypt_content(content: str) -> str:
|
||
|
|
if not content:
|
||
|
|
return ""
|
||
|
|
key, iv = make_aes()
|
||
|
|
raw = base64.b64decode(content)
|
||
|
|
cipher = AES.new(key, AES.MODE_CBC, iv)
|
||
|
|
return unpad(cipher.decrypt(raw), 16).decode("utf-8")
|
||
|
|
|
||
|
|
|
||
|
|
headers = {
|
||
|
|
"User-Agent": UA,
|
||
|
|
"Referer": BASE + "/",
|
||
|
|
"Accept": "application/json, text/plain, */*",
|
||
|
|
}
|
||
|
|
|
||
|
|
# Find SearchH5 bundle
|
||
|
|
html = requests.get(BASE, headers=headers, timeout=30).text
|
||
|
|
for m in re.finditer(r"SearchH5\.[a-f0-9]+\.js", html):
|
||
|
|
print("SearchH5:", m.group())
|
||
|
|
|
||
|
|
# Try search endpoints from JS
|
||
|
|
search_paths = [
|
||
|
|
"/novel/searchNovel?keyword=天官&page=1",
|
||
|
|
"/novel/searchNovel?keyword=天官&page=1&module=all",
|
||
|
|
"/novel/search?keyword=天官&page=1",
|
||
|
|
"/search/novel?keyword=天官&page=1",
|
||
|
|
]
|
||
|
|
for p in search_paths:
|
||
|
|
r = requests.get(WEBAPI + p, headers=headers, timeout=30)
|
||
|
|
print(p, r.status_code, r.text[:200])
|
||
|
|
|
||
|
|
# Try novel with more words - browse from homepage API
|
||
|
|
for p in [
|
||
|
|
"/novel/getNovelListByType?type_id=75&page=1&num=5",
|
||
|
|
"/novel/getNovelList?type_id=75&page=1&num=5",
|
||
|
|
"/novel/novelList?type_id=75&page=1&num=5",
|
||
|
|
]:
|
||
|
|
r = requests.get(WEBAPI + p, headers=headers, timeout=30)
|
||
|
|
print(p, r.status_code, r.text[:300])
|
||
|
|
|
||
|
|
# Test another novel id from author list
|
||
|
|
r = requests.get(
|
||
|
|
WEBAPI + "/novel/getSimpleAuthorNovelList?page=1&num=5&aid=239902",
|
||
|
|
headers={**headers, "Referer": f"{BASE}/novel-429598.html"},
|
||
|
|
timeout=30,
|
||
|
|
)
|
||
|
|
print("author novels", r.text[:500])
|