Bulk-download images from a Wikipedia page¶
Grab all the images on a single Wikipedia page at their original size. I had an AI agent combine two CLIs I already had (URL extraction and bulk download). Combining CLIs seems better than having the agent fetch things directly.
Steps¶
- Pull the links out of the page's HTML
- Rewrite thumbnail URLs into original-image URLs, then filter with a regex
- Feed the one-URL-per-line list into the bulk downloader
urlgrep 'https://en.wikipedia.org/wiki/<ページ>' \
-s '#^https://thumb\.wikimedia\.org/(.*)/thumb/([0-9a-f]/[0-9a-f]{2}/[^/]+)/[^/?]+(\?.*)?$#https://upload.wikimedia.org/\1/\2#' \
-p '/<ファイル名の共通部分>' \
| urldl - -o .scratch/images -j 2 --user-agent '<ツール名> (<連絡先>)'
The two CLIs¶
Both are small Python scripts (Typer). They're connected by a pipe, with one-URL-per-line text in between.
urlgrep — extract and filter URLs from HTML¶
urlgrep <URL | ファイル | -> [-p 正規表現]... [-x 正規表現]... [-s '#REGEX#REPL']...
- Input is a URL, a local HTML file, or stdin (
-). You can pass several at once. For files and stdin, use--baseto set the base for relative links - It extracts from tag attributes (
href/src/srcset/data-*). With--raw(the default), it also picks up barehttps?://inside scripts and JSON -pis a regex to keep (repeat = OR),-xis a regex to drop,-iignores case. Matching happens after resolving to absolute URLs-srewrites URLs before matching. sed-style'#REGEX#REPL'(the first character is the delimiter, Python regex,\1for backreferences). Repeat it to apply in order- Output is just URLs on stdout (duplicates removed by default). Summaries like counts go to stderr, so
> urls.txtgives you the list as is - Links rendered by JS are invisible. Only what's in the fetched HTML
urldl — bulk-download a URL list¶
urldl <リストファイル | -> -o <保存先> [-j 並列数] [--user-agent ...]
- Input is a one-URL-per-line file or stdin (
-). Blank lines and#comment lines are ignored - The filename is the last path segment of the URL. If a file with the same name already exists, it's skipped (
--overwriteto overwrite) -jfor concurrency (default 8),--user-agent,--timeout- To get the failures, just run the same command again. Existing files are skipped, so only the missing ones are fetched
Reusable points¶
- From thumbnail to original: what's embedded in the page are thumbnails like
thumb.wikimedia.org/.../thumb/9/90/X.jpg/120px-X.jpg. Drop/thumb/and the trailing120px-X.jpgand you get the original atupload.wikimedia.org/.../9/90/X.jpg - Rewrite, then filter: filtering and deduplication apply to the rewritten URLs. However many thumbnail variants of the same original there are, they collapse into one line
- Wikimedia blocks hammering: keep concurrency at 2 or less. Put a tool name and contact info in the User-Agent (their User-Agent policy)
- Let the agent assemble it: the agent only writes two commands and a regex. The CLIs do the actual fetching, so retrying and checking are fast
Created 2026-10-13 · Updated 2026-11-07 · Machine-translated from the Japanese original.