diff options
Diffstat (limited to 'examples')
| -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]; +} |