Skip to content

Instantly share code, notes, and snippets.

@leandroz
Created December 2, 2022 15:50
Show Gist options
  • Save leandroz/0aa814c259c46aeb34b2fab39ab3340e to your computer and use it in GitHub Desktop.
Save leandroz/0aa814c259c46aeb34b2fab39ab3340e to your computer and use it in GitHub Desktop.
Example Coda Pack to make a request and parse the result using Cheerio.
import * as coda from "@codahq/packs-sdk";
import cheerio from "cheerio";
export const pack = coda.newPack();
pack.addNetworkDomain(""); // TODO: replace with the domain you are interested in.
pack.addFormula({
name: "Parse",
description: "Parses a website to get a value.",
parameters: [
coda.makeParameter({
type: coda.ParameterType.String,
name: "url",
description: 'Url you want to parse.',
}),
coda.makeParameter({
type: coda.ParameterType.String,
name: "selector",
description: 'Selector to get the data.',
})
],
examples: [],
resultType: coda.ValueType.String,
execute: async function ([url, selector], context) {
const {body} = await context.fetcher.fetch({
url,
method: "GET",
cacheTtlSecs: 0,
});
const $ = cheerio.load(body);
return $(selector).text();
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment