3 ms·
I'd pick any CLI I can use directly in bash vs having to write Python to use a lib any day of the week.
by bsnnkv 4y ago
I'd pick any CLI I can use directly in bash vs having to write Python to use a lib any day of the week.
- culi 4y agoI had a recent realizing that Deno is actually an amazing tool for scripts and webscraping. It runs TS natively so I can take advantage of TypeScript's amazing type system when interacting with complex APIs. Being able to import libraries from a url also makes it a breeze to use any libraries (I've yet to run into a node module that Deno's std/node library wasn't able to polyfill). I can basically write a .ts file anywhere and run it from the CLI with deno. Definitely prefer it over python at this point
- brigandish 4y agoI use Deno for linting, having a binary there instead of using NPM to get a linter is a different level of simple. I like your idea, though I rarely use js for scripts I'm sure it'll come in handy.
- bryanrasmussen 4y agoIs there any situation where you end up using the type system for interacting with APIs but also have to webscrape on the same service? I am interested in hearing more about this as maybe I should switch from Node to Deno for a scraping project I have.
- culi 4y agoI haven't done something like that yet, but I'm sure there would be. Most webscraping libraries have good `@types` definitions now though which really comes in handy for at least using the tools You can probably try it in a few minutes if you already have Deno installed. Make a new file. Here's a quick example script ```ts /* run with `deno run --allow-net demo.ts` */ import { DOMParser } from 'https://deno.land/x/deno_dom/deno-dom-wasm.ts'; const API_URL = 'https://subsidytracker.goodjobsfirst.org/parent/tesla-inc'; const main = async (args: string[]) => { const resp = await fetch(API_URL); const text = await resp.text(); const html = new DOMParser().parseFromString(text, 'text/html'); console.log( 'Tesla subsidies:', [ ...html.querySelectorAll('table:first-of-type > tbody:first-of-type > tr') ].map(tr => { const [name, value] = [...tr.querySelectorAll('td')]; return { name: name.textContent, value: value.textContent }; }) ); }; main(Deno.args); ``` save that file and run: deno run --allow-net demo.ts