first commit

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
kunkunxiaomaoandClaude committed 2026-11-16 20:45:22 +08:00
commit 9c5fef1a4d
412 files changed
+94582

No files matched your search

+228
View File
@@ -0,0 +1,228 @@
#!/usr/bin/env python3
"""
代码统计与文档生成工具
功能:
1. 统计项目代码数量
2. 生成目录结构
3. 将所有代码保存到docx文档
"""
import os
import re
from docx import Document
from docx.shared import Pt, RGBColor, Cm
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
class CodeStatistics:
"""代码统计类"""
def __init__(self):
self.project_root = '.'
self.exclude_dirs = ('.venv', '.git', '.idea', '__pycache__', 'reports', 'models')
self.exclude_files = ('generate_code_doc.py',)
def analyze(self):
"""执行完整分析"""
print("🔍 正在分析项目代码...")
# 获取项目结构
structure = self._get_structure()
# 统计信息
stats = self._calculate_stats(structure)
# 生成目录树
tree = self._generate_tree(structure)
# 生成文档
self._generate_document(structure, stats, tree)
return stats
def _get_structure(self) -> dict:
"""获取项目结构"""
structure = {}
for root, dirs, files in os.walk(self.project_root):
dirs[:] = [d for d in dirs if d not in self.exclude_dirs]
for f in files:
if f.endswith('.py') and f not in self.exclude_files:
rel_path = os.path.relpath(root, self.project_root)
if rel_path not in structure:
structure[rel_path] = []
structure[rel_path].append(f)
return structure
def _calculate_stats(self, structure: dict) -> dict:
"""计算统计信息"""
stats = {
'files': 0,
'lines': 0,
'functions': 0,
'comments': 0,
'empty_lines': 0,
'size': 0,
'file_details': []
}
for directory, files in structure.items():
for filename in files:
filepath = os.path.join(self.project_root, directory, filename) if directory != '.' else filename
try:
with open(filepath, 'r', encoding='utf-8', errors='ignore') as fp:
content = fp.read()
lines = content.splitlines()
func_count = len(re.findall(r'^\s*(def|class)\s+', content, re.M))
comment_lines = sum(1 for line in lines if line.strip().startswith('#') or
(line.strip().startswith('"""') or line.strip().startswith("'''")))
empty_lines = sum(1 for line in lines if line.strip() == '')
stats['files'] += 1
stats['lines'] += len(lines)
stats['functions'] += func_count
stats['comments'] += comment_lines
stats['empty_lines'] += empty_lines
stats['size'] += len(content.encode('utf-8'))
stats['file_details'].append({
'name': filename,
'dir': directory,
'lines': len(lines),
'size': len(content.encode('utf-8'))
})
except Exception as e:
print(f"⚠️ 跳过文件: {filename} - {e}")
return stats
def _generate_tree(self, structure: dict) -> str:
"""生成目录树"""
tree = ["📁 SQL注入检测工具"]
for directory, files in sorted(structure.items()):
dir_name = directory if directory != '.' else '根目录'
tree.append(f"├── 📂 {dir_name}")
for filename in sorted(files):
tree.append(f"│ └── 📄 {filename}")
return '\n'.join(tree)
def _generate_document(self, structure: dict, stats: dict, tree: str):
"""生成docx文档"""
print("📝 正在生成文档...")
doc = Document()
# 设置页面边距
for section in doc.sections:
section.top_margin = Cm(2.54)
section.bottom_margin = Cm(2.54)
section.left_margin = Cm(2.54)
section.right_margin = Cm(2.54)
# 标题页
title = doc.add_heading('SQL注入检测工具', level=1)
title.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
title.runs[0].font.size = Pt(24)
title.runs[0].font.color.rgb = RGBColor(0, 51, 102)
subtitle = doc.add_heading('项目代码文档', level=2)
subtitle.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
subtitle.runs[0].font.size = Pt(16)
subtitle.runs[0].font.color.rgb = RGBColor(68, 68, 68)
# 目录页
doc.add_page_break()
doc.add_heading('📋 目录', level=1)
idx = 1
for directory, files in sorted(structure.items()):
dir_name = directory if directory != '.' else '根目录'
doc.add_paragraph(f"{idx}. {dir_name}")
jdx = 1
for filename in sorted(files):
doc.add_paragraph(f" {idx}.{jdx} {filename}")
jdx += 1
idx += 1
# 目录结构页
doc.add_page_break()
doc.add_heading('🌳 项目目录结构', level=1)
tree_para = doc.add_paragraph(tree)
tree_para.runs[0].font.name = 'Consolas'
tree_para.runs[0].font.size = Pt(10)
# 统计页
doc.add_page_break()
doc.add_heading('📊 项目统计', level=1)
stats_table = doc.add_table(rows=7, cols=2)
stats_table.style = 'Table Grid'
stats_data = [
('统计项', '数值'),
('Python文件数', str(stats['files'])),
('代码总行数', str(stats['lines'])),
('有效代码行', str(stats['lines'] - stats['empty_lines'])),
('函数/类数量', str(stats['functions'])),
('注释行数', str(stats['comments'])),
('总大小', f"{stats['size'] / 1024:.1f} KB")
]
for row, (label, value) in enumerate(stats_data):
stats_table.rows[row].cells[0].text = label
stats_table.rows[row].cells[1].text = value
# 文件排行
doc.add_heading('📁 文件大小排行', level=2)
sorted_files = sorted(stats['file_details'], key=lambda x: x['size'], reverse=True)[:10]
rank_table = doc.add_table(rows=11, cols=3)
rank_table.style = 'Table Grid'
rank_table.rows[0].cells[0].text = '排名'
rank_table.rows[0].cells[1].text = '文件'
rank_table.rows[0].cells[2].text = '大小(KB)'
for i, file_info in enumerate(sorted_files, 1):
rank_table.rows[i].cells[0].text = str(i)
rank_table.rows[i].cells[1].text = file_info['name']
rank_table.rows[i].cells[2].text = f"{file_info['size'] / 1024:.1f}"
# 代码内容
for directory, files in sorted(structure.items()):
doc.add_page_break()
dir_name = directory if directory != '.' else '根目录'
doc.add_heading(f"📂 {dir_name}", level=1)
for filename in sorted(files):
filepath = os.path.join(self.project_root, directory, filename) if directory != '.' else filename
try:
with open(filepath, 'r', encoding='utf-8', errors='ignore') as fp:
content = fp.read()
doc.add_heading(f"📄 {filename}", level=2)
doc.add_paragraph("-" * 80)
code_para = doc.add_paragraph()
code_run = code_para.add_run(content)
code_run.font.name = 'Consolas'
code_run.font.size = Pt(9)
doc.add_paragraph()
except Exception as e:
doc.add_paragraph(f"⚠️ 无法读取: {filename} - {e}")
doc.save('下载器项目代码文档.docx')
print("✅ 文档生成完成")
def main():
analyzer = CodeStatistics()
stats = analyzer.analyze()
print("\n" + "=" * 60)
print("📊 项目代码统计结果")
print("=" * 60)
print(f"📄 Python文件数: {stats['files']}")
print(f"📝 代码总行数: {stats['lines']}")
print(f"🔧 函数/类数量: {stats['functions']}")
print(f"📝 注释行数: {stats['comments']}")
print(f"📦 总大小: {stats['size'] / 1024:.1f} KB")
print("=" * 60)
print(f"📄 文档已保存: 下载器项目代码文档.docx")
print("=" * 60)
if __name__ == '__main__':
main()
+51
View File
@@ -0,0 +1,51 @@
"""Probe gongzicp.com HTML/API structure."""
from __future__ import annotations
import json
import re
import requests
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0"
BASE = "https://www.gongzicp.com"
def fetch(path: str) -> str:
url = path if path.startswith("http") else f"{BASE}{path}"
r = requests.get(url, headers={"User-Agent": UA, "Referer": BASE + "/"}, timeout=45)
print(f"GET {url} -> {r.status_code} len={len(r.text)}")
return r.text
def main() -> None:
html = fetch("/novel-429598.html")
# API hints
for line in html.splitlines():
lower = line.lower()
if any(k in lower for k in ("api", "chapter", "catalog", "novelid", "read")):
if len(line.strip()) < 300:
print(line.strip()[:200])
# chapter links
chapters = re.findall(r'href="([^"]*chapter[^"]*)"', html, re.I)
print("chapter hrefs sample:", chapters[:10])
chapters2 = re.findall(r'href="(/read/\d+[^"]*)"', html)
print("read hrefs:", chapters2[:10])
chapters3 = re.findall(r'novel-\d+', html)
print("novel ids in page:", list(set(chapters3))[:5])
print("html preview:", html[:2000])
# try search API guesses
for api in [
"/webapi/search/novel?keyword=测试",
"/api/search?keyword=测试",
"/search?keyword=测试",
]:
try:
t = fetch(api)
print(t[:500])
except Exception as exc:
print(api, exc)
if __name__ == "__main__":
main()
+41
View File
@@ -0,0 +1,41 @@
import json
import requests
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0"
BASE = "https://www.gongzicp.com/webapi"
headers = {
"User-Agent": UA,
"Referer": "https://www.gongzicp.com/novel-429598.html",
"Accept": "application/json, text/plain, */*",
}
paths = [
"/novel/novelInfo?id=429598",
"/novel/chapterGetList?nid=429598",
]
for p in paths:
r = requests.get(BASE + p, headers=headers, timeout=30)
print(p, r.status_code)
data = r.json()
print(json.dumps(data, ensure_ascii=False)[:1500])
# chapter content - need cid from chapter list
clist = requests.get(BASE + "/novel/chapterGetList?nid=429598", headers=headers, timeout=30).json()
items = clist.get("data", {}).get("list") or []
print("chapters", len(items))
if items:
cid = items[0].get("id")
r = requests.get(
BASE + f"/novel/chapterGetInfo?nid=429598&cid={cid}",
headers=headers,
timeout=30,
)
print("chapter info", r.status_code, json.dumps(r.json(), ensure_ascii=False)[:800])
# search
r = requests.get(
BASE + "/novel/searchNovel?keyword=天官&page=1&module=all",
headers={**headers, "Referer": "https://www.gongzicp.com/"},
timeout=30,
)
print("search", r.status_code, r.text[:800])
+76
View File
@@ -0,0 +1,76 @@
"""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])
+37
View File
@@ -0,0 +1,37 @@
import json
import requests
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0"
BASE = "https://www.gongzicp.com"
WEBAPI = BASE + "/webapi"
headers = {
"User-Agent": UA,
"Referer": BASE + "/",
"Accept": "application/json, text/plain, */*",
}
s = requests.Session()
s.headers.update(headers)
init = s.get(WEBAPI + "/system/init", timeout=30).json()
print("init", init)
# chapter with nid param
for nid, cid in [(429598, 2377724), (100000, 1)]:
r = s.get(
WEBAPI + f"/novel/chapterGetInfo?nid={nid}&cid={cid}",
headers={"Referer": f"{BASE}/read-{nid}-{cid}.html"},
timeout=30,
)
data = r.json()
if data.get("code") == 200:
ci = data.get("data", {}).get("chapterInfo", {})
print(nid, cid, "content len", len(ci.get("content") or ""), "number", ci.get("number"))
# try search with session cookies
r = s.get(
WEBAPI + "/novel/searchNovel",
params={"keyword": "天官", "page": 1, "num": 10},
headers={"Referer": f"{BASE}/search.html"},
timeout=30,
)
print("search", r.status_code, r.text[:500])
+13
View File
@@ -0,0 +1,13 @@
import re
import requests
html = requests.get("https://www.gongzicp.com/", timeout=30).text
for m in re.finditer(r"/assets/[^\"']*Search[^\"']*\.js", html):
print("bundle", m.group())
for m in re.finditer(r"/assets/index\.[a-f0-9]+\.js", html):
jsurl = "https://www.gongzicp.com" + m.group()
t = requests.get(jsurl, timeout=60).text
for m2 in re.finditer(r".{0,60}searchNovel.{0,100}", t):
print(m2.group()[:220])
print("---")
+28
View File
@@ -0,0 +1,28 @@
import json
import requests
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0"
BASE = "https://www.gongzicp.com"
WEBAPI = BASE + "/webapi"
headers = {
"User-Agent": UA,
"Referer": BASE + "/",
"Accept": "application/json, text/plain, */*",
}
paths = [
"/home/typeList?tid=75&page=1&num=10",
"/home/getTypeList?tid=75&page=1&num=10",
"/novel/getTypeNovelList?type_id=75&page=1&num=10",
"/novel/novelListByType?type_id=75&page=1&num=10",
"/rank/getRankList?type=1&page=1&num=10",
"/novel/getRankNovelList?rank_type=1&page=1&num=10",
]
for p in paths:
try:
r = requests.get(WEBAPI + p, headers=headers, timeout=30)
text = r.text
if '"code":200' in text or '"code": 200' in text:
print("OK", p, text[:400])
except Exception as ex:
print("ERR", p, ex)
+20
View File
@@ -0,0 +1,20 @@
import re
import requests
html = requests.get("https://www.gongzicp.com/", timeout=30).text
for m in re.finditer(r"/assets/[A-Za-z0-9_.-]+\.js", html):
name = m.group()
if "Home" in name or "Type" in name or "Search" in name:
print(name)
# grep all js from index.eef719ce for webapi paths
t = requests.get("https://www.gongzicp.com/assets/index.eef719ce.js", timeout=60).text
for m in re.finditer(r"/[a-zA-Z]+/[a-zA-Z]+[a-zA-Z0-9]*", t):
s = m.group()
if "novel" in s.lower() or "search" in s.lower() or "home" in s.lower() or "type" in s.lower():
if len(s) < 40:
pass
for m in re.finditer(r"url:\s*[\"']/[^\"']+[\"']", t):
s = m.group()
if any(k in s for k in ("novel", "search", "home", "type", "rank")):
print(s)
+16
View File
@@ -0,0 +1,16 @@
import re
import requests
t = requests.get("https://www.gongzicp.com/assets/index.eef719ce.js", timeout=60).text
# find webapi base
for m in re.finditer(r"webapi[^\"']{0,40}", t):
print(m.group()[:80])
# find all strings containing GetList or search
seen = set()
for m in re.finditer(r"[\"'][/][a-zA-Z]+/[a-zA-Z][a-zA-Z0-9]*[\"']", t):
s = m.group().strip("'\"")
if any(k in s.lower() for k in ("novel", "search", "home", "rank", "type")):
if s not in seen:
seen.add(s)
print(s)
+8
View File
@@ -0,0 +1,8 @@
import re
import requests
t = requests.get("https://www.gongzicp.com/assets/index.eef719ce.js", timeout=60).text
for m in re.finditer(r"[\"']\./[A-Za-z0-9_.-]+\.js[\"']", t):
name = m.group()
if "Search" in name or "Home" in name or "Type" in name or "novel" in name.lower():
print(name)
+16
View File
@@ -0,0 +1,16 @@
import re
import requests
chunks = [
"SearchH5.1c778303.js",
"TypeH5.e1133e1d.js",
"HomeH5.2bbaaa98.js",
"NovelListH5.a284bf69.js",
]
for chunk in chunks:
t = requests.get(f"https://www.gongzicp.com/assets/{chunk}", timeout=60).text
print("===", chunk, "len", len(t))
for m in re.finditer(r"url:\s*[\"'][/][^\"']+[\"']", t):
print(m.group())
for m in re.finditer(r"[\"']/novel/[a-zA-Z]+[\"']", t):
print(m.group())
+21
View File
@@ -0,0 +1,21 @@
import json
import requests
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0"
BASE = "https://www.gongzicp.com"
WEBAPI = BASE + "/webapi"
headers = {
"User-Agent": UA,
"Referer": BASE + "/",
"Accept": "application/json, text/plain, */*",
}
def get(path, **params):
r = requests.get(WEBAPI + path, params=params, headers=headers, timeout=30)
print(path, params, r.status_code, r.text[:500])
return r
get("/search/novels", keyword="天官", page=1, num=5)
get("/novel/novelList", type_id=75, page=1, num=5)
get("/novel/typeGetList")
get("/novel/typeGetInfo", type_id=75)
+57
View File
@@ -0,0 +1,57 @@
"""Probe gongzicp webapi endpoints."""
from __future__ import annotations
import re
import requests
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0"
BASE = "https://www.gongzicp.com"
SESSION = requests.Session()
SESSION.headers.update(
{
"User-Agent": UA,
"Referer": BASE + "/",
"Accept": "application/json, text/plain, */*",
"Origin": BASE,
}
)
def get(path: str, **kwargs) -> requests.Response:
url = path if path.startswith("http") else f"{BASE}{path}"
return SESSION.get(url, timeout=45, **kwargs)
def main() -> None:
r = get("/novel-429598.html")
m = re.search(r'/assets/index\.([a-f0-9]+)\.js', r.text)
if not m:
print("no js bundle")
return
js_name = f"/assets/index.{m.group(1)}.js"
js = get(js_name).text
print(f"js len {len(js)}")
apis = sorted(set(re.findall(r"/webapi/[a-zA-Z0-9_/]+", js)))
print("webapi paths:", apis[:40])
print("total apis", len(apis))
# try novel detail
for path in [
"/webapi/novel/429598",
"/webapi/novel/detail?novel_id=429598",
"/webapi/novel/detail?novelId=429598",
"/webapi/novel/info?novel_id=429598",
"/webapi/chapter/list?novel_id=429598",
"/webapi/chapter/list?novelId=429598",
"/webapi/novel/chapter/list?novel_id=429598",
"/webapi/search/novel?keyword=天官",
]:
try:
resp = get(path)
print(path, resp.status_code, resp.text[:300])
except Exception as exc:
print(path, exc)
if __name__ == "__main__":
main()
+47
View File
@@ -0,0 +1,47 @@
import base64
import json
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"
headers = {
"User-Agent": UA,
"Referer": f"{BASE}/novel-2058540.html",
"Accept": "application/json, text/plain, */*",
}
nid = 2058540
def js_to_string(n, base):
digits = "0123456789abcdefghijklmnopqrstuvwxyz"
s = ""
while n:
s = digits[n % base] + s
n //= base
return s or "0"
def decrypt_content(content):
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"
key, iv = key_str.encode(), iv_str.encode()
raw = base64.b64decode(content)
cipher = AES.new(key, AES.MODE_CBC, iv)
return unpad(cipher.decrypt(raw), 16).decode("utf-8")
info = requests.get(WEBAPI + f"/novel/novelInfo?id={nid}", headers=headers, timeout=30).json()
print("novel", info["data"]["novel_name"], info["data"]["novel_wordnumber"])
clist = requests.get(WEBAPI + f"/novel/chapterGetList?nid={nid}", headers=headers, timeout=30).json()
chapters = clist["data"]["list"]
print("chapters", len(chapters))
for ch in chapters[:3]:
cid = ch["id"]
r = requests.get(WEBAPI + f"/novel/chapterGetInfo?nid={nid}&cid={cid}", headers=headers, timeout=30)
ci = r.json()["data"]["chapterInfo"]
enc = ci.get("content") or ""
text = decrypt_content(enc) if enc else ""
print(ch["name"][:40], "enc", len(enc), "text", len(text), text[:80].replace("\n", " "))
+7
View File
@@ -0,0 +1,7 @@
import re
import requests
t = requests.get("https://www.gongzicp.com/assets/index.eef719ce.js", timeout=60).text
for m in re.finditer(r".{0,80}search/novels.{0,120}", t):
print(m.group()[:250])
print("---")
+26
View File
@@ -0,0 +1,26 @@
import re
import requests
for chunk in ["CpListData.97f05acb.js", "CpListData.b8c8c8c8.js"]:
try:
t = requests.get(f"https://www.gongzicp.com/assets/{chunk}", timeout=30).text
print(chunk, "found", len(t))
for m in re.finditer(r".{0,100}search.{0,100}", t, re.I):
if "novel" in m.group().lower():
print(m.group()[:220])
except Exception as ex:
print(chunk, ex)
# list assets matching CpListData
html = requests.get("https://www.gongzicp.com/", timeout=30).text
for m in re.finditer(r"CpListData\.[a-f0-9]+\.js", html):
print(m.group())
t = requests.get("https://www.gongzicp.com/assets/index.eef719ce.js", timeout=60).text
for m in re.finditer(r"CpListData\.[a-f0-9]+\.js", t):
chunk = m.group()
print("loading", chunk)
ct = requests.get(f"https://www.gongzicp.com/assets/{chunk}", timeout=30).text
for m2 in re.finditer(r"params:\{[^}]{0,200}\}", ct):
if "search" in m2.group().lower() or "word" in m2.group().lower():
print(m2.group())
+19
View File
@@ -0,0 +1,19 @@
import re
import requests
js = requests.get(
"https://www.gongzicp.com/assets/index.eef719ce.js",
headers={"User-Agent": "Mozilla/5.0"},
timeout=90,
).text
for needle in ["webapi", "novel", "chapter", "search", "read"]:
idx = 0
found = 0
while found < 15:
i = js.find(needle, idx)
if i < 0:
break
snippet = js[max(0, i - 40) : i + 80]
print("---", needle, snippet.replace("\n", " "))
idx = i + len(needle)
found += 1
+39
View File
@@ -0,0 +1,39 @@
import re
import requests
js = requests.get(
"https://www.gongzicp.com/assets/index.eef719ce.js",
headers={"User-Agent": "Mozilla/5.0"},
timeout=90,
).text
for needle in ["apiv2", "getNovel", "searchNovel", "chapter", "readChapter"]:
idx = 0
found = 0
while found < 8:
i = js.find(needle, idx)
if i < 0:
break
snippet = js[max(0, i - 30) : i + 100]
print("---", needle, snippet.replace("\n", " "))
idx = i + len(needle)
found += 1
API = "https://api1.gongzicp.com/apiv2"
headers = {
"User-Agent": "Mozilla/5.0",
"Referer": "https://www.gongzicp.com/",
"Origin": "https://www.gongzicp.com",
}
paths = [
"/novel/info?novel_id=429598",
"/novel/info?novelId=429598",
"/novel/detail?novel_id=429598",
"/novel/chapter/list?novel_id=429598",
"/chapter/list?novel_id=429598",
"/search/novel?keyword=天官",
"/searchNovel?keyword=天官",
"/novel/search?keyword=天官",
]
for p in paths:
r = requests.get(API + p, headers=headers, timeout=30)
print(p, r.status_code, r.text[:400])
+46
View File
@@ -0,0 +1,46 @@
import base64
import re
import requests
auth = "Basic 6ZmI5aSn5a6dOmNwMTIzNDU2"
print("auth decode", base64.b64decode("6ZmI5aSn5a6dOmNwMTIzNDU2"))
js = requests.get(
"https://www.gongzicp.com/assets/index.eef719ce.js",
timeout=90,
headers={"User-Agent": "Mozilla/5.0"},
).text
# find function Fg or getNovels definition area
for m in re.finditer(r"getNovels[^}]{0,500}", js):
s = m.group(0)
if "apiv2" in s or "novel" in s.lower():
print(s[:400])
print("---")
# search url patterns with apiv2
urls = sorted(set(re.findall(r"apiv2/[a-zA-Z0-9_/]+", js)))
print("apiv2 paths", urls[:50])
API = "https://api1.gongzicp.com/apiv2"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0",
"Referer": "https://www.gongzicp.com/",
"Origin": "https://www.gongzicp.com",
"Authorization": auth,
}
tests = [
"/novel/info?novelid=429598",
"/novel/info?nid=429598",
"/novel/info?id=429598",
"/novel/getInfo?novelid=429598",
"/novel/chapterList?novelid=429598",
"/novel/chapterList?nid=429598",
"/chapter/content?chapterid=1&novelid=429598",
"/read/chapter?chapter_id=1&novel_id=429598",
"/searchNovel?keyword=天官&page=1",
"/novel/searchNovel?keyword=天官",
]
for p in tests:
r = requests.get(API + p, headers=headers, timeout=30)
print(p, r.status_code, r.text[:500])
+30
View File
@@ -0,0 +1,30 @@
import re
import requests
js = requests.get(
"https://www.gongzicp.com/assets/index.eef719ce.js",
timeout=90,
headers={"User-Agent": "Mozilla/5.0"},
).text
for pat in [r"novel/[a-zA-Z]+", r"chapter/[a-zA-Z]+", r"search[A-Za-z]+", r"read/[a-zA-Z]+"]:
found = sorted(set(re.findall(pat, js)))
print(pat, found[:30])
# find Fg assignment
idx = js.find("function Fg")
if idx < 0:
idx = js.find("Fg=")
print("Fg at", idx)
if idx >= 0:
print(js[idx:idx+800])
# download InfoH5 chunk
chunk = requests.get(
"https://www.gongzicp.com/assets/InfoH5.37080396.js",
timeout=60,
headers={"User-Agent": "Mozilla/5.0"},
).text
print("InfoH5 len", len(chunk))
for pat in [r"apiv2[^\"']{0,60}", r"/novel[^\"']{0,60}", r"chapter[^\"']{0,40}"]:
m = re.findall(pat, chunk)
print(pat, m[:15])
+39
View File
@@ -0,0 +1,39 @@
import json
import requests
AUTH = "Basic 6ZmI5aSn5a6dOmNwMTIzNDU2"
API = "https://api1.gongzicp.com/apiv2"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0",
"Referer": "https://www.gongzicp.com/",
"Origin": "https://www.gongzicp.com",
"Authorization": AUTH,
"Content-Type": "application/json",
}
def post(path, body):
r = requests.post(API + path, headers=headers, json=body, timeout=30)
print(path, body, r.status_code, r.text[:600])
post("/novel/novelInfo", {"novelid": 429598})
post("/novel/novelInfo", {"novelId": 429598})
post("/novel/novelInfo", {"nid": 429598})
post("/novel/novelInfo", {"id": 429598})
post("/novel/chapterGetList", {"novelid": 429598})
post("/novel/chapterGetList", {"nid": 429598})
post("/novel/chapterGetInfo", {"novelid": 429598, "chapterid": 1})
post("/novel/chapterGetInfo", {"nid": 429598, "cid": 1})
# search from SearchH5
chunk = requests.get(
"https://www.gongzicp.com/assets/SearchH5.1c778303.js",
timeout=60,
headers={"User-Agent": "Mozilla/5.0"},
).text
import re
paths = sorted(set(re.findall(r"/novel/[a-zA-Z]+", chunk)))
print("search paths", paths)
post("/novel/searchNovel", {"keyword": "天官", "page": 1, "tab": "all"})
post("/novel/searchNovel", {"word": "天官", "module": "all"})
+33
View File
@@ -0,0 +1,33 @@
import json
import requests
AUTH = "Basic 6ZmI5aSn5a6dOmNwMTIzNDU2"
API = "https://api1.gongzicp.com/apiv2"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0",
"Referer": "https://www.gongzicp.com/",
"Origin": "https://www.gongzicp.com",
"Authorization": AUTH,
"Content-Type": "application/json",
}
def call(path, params):
body = {"url": path, "params": params}
r = requests.post(API + path, headers=headers, json=params, timeout=30)
print("POST path", path, params, r.status_code, r.text[:500])
r2 = requests.post(API, headers=headers, json=body, timeout=30)
print("POST root wrap", body, r2.status_code, r2.text[:500])
call("/novel/chapterGetList", {"nid": 429598})
call("/novel/chapterGetInfo", {"nid": 429598, "cid": "1"})
call("/novel/novelInfo", {"nid": 429598})
# try webapi gateway
WEB = "https://www.gongzicp.com/webapi"
for body in [
{"url": "/novel/chapterGetList", "params": {"nid": 429598}},
{"nid": 429598},
]:
r = requests.post(WEB, headers=headers, json=body, timeout=30)
print("webapi", body, r.status_code, r.text[:500])
+41
View File
@@ -0,0 +1,41 @@
import json
import requests
AUTH = "Basic 6ZmI5aSn5a6dOmNwMTIzNDU2"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0",
"Referer": "https://www.gongzicp.com/",
"Origin": "https://www.gongzicp.com",
"Authorization": AUTH,
"Content-Type": "application/json",
}
body = {"url": "/novel/chapterGetList", "params": {"nid": 429598}}
for endpoint in [
"https://www.gongzicp.com/webapi",
"https://www.gongzicp.com/webapi/",
"https://www.gongzicp.com/webapi/novel/chapterGetList",
"https://api1.gongzicp.com/apiv2/novel/chapterGetList",
]:
r = requests.post(endpoint, headers=headers, json=body, timeout=30)
print(endpoint, r.status_code, len(r.text), r.text[:800])
# GET webapi with query?
r = requests.get(
"https://www.gongzicp.com/webapi",
headers=headers,
params={"url": "/novel/chapterGetList", "nid": 429598},
timeout=30,
)
print("GET webapi", r.status_code, r.text[:500])
# try apiv2 with form data
import urllib.parse
data = urllib.parse.urlencode({"nid": "429598"})
r = requests.post(
"https://api1.gongzicp.com/apiv2/novel/chapterGetList",
headers={**headers, "Content-Type": "application/x-www-form-urlencoded"},
data=data,
timeout=30,
)
print("form", r.status_code, r.text[:500])
+45
View File
@@ -0,0 +1,45 @@
"""Capture gongzicp API calls via Playwright."""
from __future__ import annotations
import json
from playwright.sync_api import sync_playwright
from pixiv_app.core.playwright_runtime import configure_playwright_runtime_env, preferred_chromium_executable
def main() -> None:
configure_playwright_runtime_env()
calls: list[dict] = []
with sync_playwright() as p:
browser = p.chromium.launch(
headless=True,
executable_path=preferred_chromium_executable(),
)
context = browser.new_context(
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0",
)
page = context.new_page()
def on_request(request):
url = request.url
if "gongzicp" in url and ("apiv2" in url or "webapi" in url):
post = request.post_data or ""
calls.append(
{
"url": url,
"method": request.method,
"post": post[:2000],
}
)
page.on("request", on_request)
page.goto("https://www.gongzicp.com/novel-429598.html", wait_until="networkidle", timeout=120000)
page.wait_for_timeout(5000)
browser.close()
print(json.dumps(calls, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
+21
View File
@@ -0,0 +1,21 @@
"""Quick smoke test for changpei plugin."""
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
from pixiv_app.core.plugin.manager import PluginManager
manager = PluginManager([ROOT / "plugins"])
plugin = manager.load_plugin(ROOT / "plugins" / "changpei" / "plugin.py")
assert plugin is not None
print("loaded", plugin.name, plugin.version)
outcome = plugin.resolve_target("2058540")
resources = outcome["resources"]
print("chapters", len(resources), outcome["book_title"])
chapter = resources[1]
paths = plugin.download(chapter, ROOT / ".tmp_changpei_test")
print("saved", paths[0], paths[0].stat().st_size)