Scripts to probe a book's TOC, print each page-level item to PDF via the print popup, verify, merge per 대항목 and clean up temp files. Invoked only by /lawnb-pdf-download (disable-model-invocation). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
6.6 KiB
6.6 KiB
name, disable-model-invocation, description
| name | disable-model-invocation | description |
|---|---|---|
| lawnb-pdf-download | true | Use when asked to save LAWnB (로앤비 전자법률도서관) 주석서 pages as PDF files — click a TOC item (장·절·조·총설·전론·후론), press 인쇄, "save as PDF", rename, merge per 대항목 and delete the temp files. Covers 주석 민법, 주석 상법, 주석 민사소송법 and similar books on academynext-lawnb-com.libra.cnu.ac.kr via ego-browser. Draft; verify the page structure before trusting it. |
LAWnB 주석서 → PDF
Repeats the manual "목차 항목 클릭 → 우측 상단 인쇄 → PDF로 저장" flow for many items, then merges the per-item PDFs into one file per 대항목 and deletes the temp PDFs. Built from ~25 runs (채권총칙·채권각칙·상속법·상법, ~1,100 pages printed). Personal research use under the library's licence only; save one file per requested item and do not redistribute.
Read the ego-browser skill first (ego-browser skill). Scripts here are templates for ego-browser nodejs.
Prerequisites
- Someone is logged in to the library proxy in ego lite (the print layer calls
/Login/GetLoginChk). - Run every
ego-browsercommand with the sandbox disabled (it must launch the app), and every command that writes to the user's destination folder too (the sandbox only allows writes under the working directory). Keep the temp PDFs in the session scratchpad dir. - The user's own visible tab cannot be controlled (it is not in a task space). Open the same book URL in an agent task space; the result is identical because each page is addressed by id.
Workflow
- Find the book. Run
scripts/find_books.js. A book = the sid prefix, e.g.D021FC603232FC8E(채권총칙),D021436693BDE2F6(채권각칙),D021D0E9032210F7(상속법),D0216150ACD3F2DF(상법 총칙·상행위),D021E22544FFC822(상법 보험). Confirm the book name on the opened page (line after "로앤비"), not from memory. Book URL =https://academynext-lawnb-com.libra.cnu.ac.kr/Info/ContentView?sid=<BOOK>_<anyNodeId>. - Probe the TOC. Render
scripts/probe_toc.jswith{bookUrl, rootRegex, depth}and read the tree. Decide: which children are 대항목, whether a 절/관 is a link-less group, how many pages each has. Compare with the user's request: the user's ranges and names can contain typos (e.g. 제527조~제533조 vs ~제553조); use the site and say so. - Print. Render
scripts/print_items.jswith the groups (key+ regex on the child's own text). Fewer than ~40 pages: run in the foreground. More:run_in_background(foreground limit is 10 min, ~10 s per page; stdout appears only at the end, so check progress by counting files in tmpDir). A rerun skips existing files. - Verify with
scripts/verify_pdfs.py <tmpDir>: duplicates, article heading vs filename, empty files. Look at every총설/전론first heading line. Check the printed log forFAILandSAVED-UNVERIFIED. - Merge with
scripts/merge_pdfs.py config.json(pdfunite; page sums compared; temp files deleted only if everything matched). Final names = exactly what the user gave; add nothing else unless told, and report any extra file you made. - Report: per output file name, page count, number of merged items, anything deviating from the request.
Render a template: python3 scripts/render.py scripts/print_items.js cfg.json $SCRATCH/run.js && ego-browser nodejs < $SCRATCH/run.js
How the site works (what the scripts rely on)
- Every page-level TOC anchor has
href="javascript:doc.showTargetContent('<BOOK>|<id>|R1')". Call that function directly; no click needed. Roman-numeral sub-headings (Ⅰ, Ⅱ ...) have three-part ids (<BOOK>|<id>|<id2>|R1) and are sections of the same page — never print them separately. - 인쇄: click
#pring_set→ a layer opens → click its인쇄button (find by text, click by coordinates) → a popupContentPrintViewopens. The browser's native print dialog is not automatable, so the scripts runPage.printToPDFon that popup instead. Say this to the user: same content, page breaks may differ slightly. - The popup prints the whole subtree of the selected item (an article with 150 sub-sections gives 150+ pages).
- 절/관/장 nodes are usually link-less
<li>(text node only) or anchors without a page id. The 대항목 for such a node = every page anchor beneath it, in TOC order (including 총설, 전론, 후론, 부칙, 보론, nested 관). - TOC text uses
[총설],[전론 : ...],[후론2 : ...],제22조의2,제4장의2; match with regexes that allow의N.
Pitfalls (each one cost a rerun)
- Stale page. Printing before the new page is rendered saves the previous page (제741조 came out as 총설).
The script waits 4.5 s+, checks the popup text contains the title and differs from the last page, and retries.
Raise
waitMsif mismatches appear. - Env vars and argv do not reach ego scripts. Inject config text (render.py). Heredoc or
< fileonly. - Shell. The shell is zsh: arrays are 1-indexed and
$varis not word-split. Use the Python scripts for loops/merging. Sort numerically (item 100+ sorts before 11 as text). - Key collisions.
제4장vs제4장의2need(?:의(\d+))?in the key regex; temp file keys like4and4_2must not match each other (merge_pdfs.py uses\d{2,}for NN). - Timeouts/killing. A foreground run is killed at 10 min. Use background + rerun. Kill a hung run with
pkill -f "ego-browser nodejs"only when you started it. - Deleting temp files. Write
rm "${T:?}"/*.pdf— the safety check rejects an unguarded$T. Delete only the temp PDFs you created. merge_pdfs.py already does this (deleteTmp: true). - One group, one file. A 대항목 with a single page is merged by copying; the individual and merged files are then identical, which is fine.
- Items with only
Ⅰ.sub-headings and no own page id (e.g. 노동관계법 in 불법행위) are single pages.
Config examples
print_items (상법 제2편 제6·7장):
{"task": "lawnb 상법2 6-7",
"bookUrl": "https://academynext-lawnb-com.libra.cnu.ac.kr/Info/ContentView?sid=D0216150ACD3F2DF_100266",
"rootRegex": "^제2편 상행위",
"groups": [{"key": "6", "match": "^제6장"}, {"key": "7", "match": "^제7장"}],
"tmpDir": "/abs/scratchpad/tmp_sb/"}
merge_pdfs:
{"tmpDir": "/abs/scratchpad/tmp_sb", "destDir": "/abs/.../주석_상법",
"prefix": "주석상법_제2편_", "groups": [["6", "제6장_중개업"], ["7", "제7장_위탁매매업"]], "deleteTmp": true}
Use "^제4장(?!의)" for 제4장 and "^제4장의2" for 제4장의2.