Por Anthony | Actualizada un mese fa | Data

9.9 / 10



Nivel de servicio


Health Check


Volver a todas las conversaciones

Having trouble with extractor.

Rapid account: Ed 8 Mame
2 mesi fa

I am attempting to pass a function to the extractor key of the payload object and for all the different variations I have tried I continue to receive extractor errors in my response.

Here is my most recent attempt using the same extractor function from ScrapeNinjaLiveSandbox for scrapping metadata.

The following code: “extractor”: “function (input, cheerio) {\n let $ = cheerio.load(input);\n let data = { \n image: $(‘meta[property=“og:image”]’).attr(‘content’),\n favicon: $(‘link[rel=“icon”]’).attr(“href”) ||\n $(‘link[rel=“shortcut icon”]’).attr(“href”),\n url: $(‘link[rel=“canonical”]’).attr(“href”),\n title: $(‘title’).text().trim(),\n description: $(‘meta[name=description]’).attr(‘content’),\n }\n \n let regex = /https?:\/\/?[\/]+/;\n // if relative url in files found - try to make it absolute\n if (data.url) {\n let m = data.url.match(regex);\n if (data.image && data.image[0] == ‘/’) {\n \tdata.image = m[0] + data.image;\n }\n \n if (data.favicon && data.favicon[0] == ‘/’) {\n \tdata.favicon = m[0] + data.favicon;\n }\n \n }\n \n return data;\n}”

Returns this error: target website extractor: { err: “Error: SyntaxError: Unexpected token ‘;’” }

My full code:
exports.myFunction = onRequest(async (_req: any, _res: any) => {
const url = “”;

const PAYLOAD = {
    "url": "",
    "method": "GET",
    "retryNum": 1,
    "geo": "us",
    "extractor": extract,

const options = {
method: “POST”,
headers: {
“content-type”: “application/json”,
“X-RapidAPI-Key”: “REMOVED”,
“X-RapidAPI-Host”: “”,
body: JSON.stringify(PAYLOAD),

try {
let res = await fetch(url, options);
let resJson = await res.json();

// Basic error handling. Modify if neccessary
if (! || ![200, 404].includes( {
  throw new Error(JSON.stringify(resJson));

console.log("target website extractor", resJson.extractor);

} catch (e) {

Am I doing something wrong?

Rapid account: Restyler
restyler Commented 2 mesi fa

Hi! RapidAPI formatting corrupts the code and it’s hard to copy&paste it into code editor from here. Can you please send you node.js script to so I can look into it? (please attach the code as .txt attachment). You can also use any codepen-like website or github gists to paste your code and just send me the link.

Únase a la conversación, añada un comentario a continuación:

Inicie sesió/Regístrese para publicar nuevos comentarios