57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
"""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()
|