diff options
| author | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-11-15 16:31:50 +0100 |
|---|---|---|
| committer | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-11-15 23:54:03 +0100 |
| commit | 94da9293f63e46712b0a890e1e0eab4153fdb3f9 (patch) | |
| tree | de81e6d00f7e1a5215d18557e772e7f1131d218b /examples/download.js | |
| parent | 3e01902887bdc52e743ef6cec53a5c89cb5637f0 (diff) | |
Add file download functionality
Diffstat (limited to 'examples/download.js')
| -rw-r--r-- | examples/download.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/download.js b/examples/download.js new file mode 100644 index 0000000..7048846 --- /dev/null +++ b/examples/download.js @@ -0,0 +1,25 @@ +import { download } from "flyscrape/http"; + +export const config = { + url: "https://commons.wikimedia.org/wiki/London", +}; + +export default function ({ doc }) { + const symbols = doc.find("#mw-content-text .mw-gallery-traditional:first-of-type li"); + + return { + symbols: symbols.map(symbol => { + const name = symbol.text().trim(); + const url = symbol.find("img").attr("src"); + const file = `symbols/${basename(url)}`; + + download(url, file); + + return { name, url, file }; + }) + }; +} + +function basename(path) { + return path.split("/").slice(-1)[0]; +} |