Created
December 2, 2022 15:50
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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