Problems with ScraperNinja

Hi,

Im using the module ScraperNinja. I’m having problems with the Extractor JS. The Extractor JS i’m using is working on their playground (ScrapeNinja Live Sandbox) but on Make. This dosent make any sense.

Example URL im scraping: https: // www. finn.no/realestate/homes/ad.html?finnkode=346814072&ci=18

The Extractor JS:

function (input, cheerio) {
let $ = cheerio.load(input);
let data = {
image: $(‘meta[property=“og:image”]’).attr(‘content’),
favicon: $(‘link[rel=“icon”]’).attr(“href”) ||
$(‘link[rel=“shortcut icon”]’).attr(“href”),
url: $(‘link[rel=“canonical”]’).attr(“href”),
title: $(‘title’).text().trim(),
description: $(‘meta[name=description]’).attr(‘content’),
h1: $(‘h1’).text().trim(),
priceValue: $(‘div[data-testid=“pricing-incicative-price”] span.text-28.font-bold’).text().trim() || ‘’,
totalPrice: $(‘div[data-testid=“pricing-total-price”] dd.font-bold’).text().trim() || ‘’,
address: $(‘a[data-testid=“map-link”] span[data-testid=“object-address”]’).text().trim() || ‘’,
pRom: $(‘div[data-testid=“info-primary-area”] dd.font-bold’).text().trim().replace(/\D/g, ‘’) || ‘’,
tomteareal: $(‘div[data-testid=“info-plot-area”] dd.font-bold’).text().trim().replace(/\D/g, ‘’) || ‘’,
soverom: $(‘div[data-testid=“info-rooms”] dd.font-bold’).text().trim() || ‘’,
byggeaar: $(‘div[data-testid=“info-construction-year”] dd.font-bold’).text().trim() || ‘’,
boligtype: $(‘div[data-testid=“info-property-type”] dd.font-bold’).text().trim() || ‘’,
fellesgjeld: $(‘div[data-testid=“pricing-joint-debt”] dd.font-bold’).text().trim() || ‘’
}

let regex = /^https?://?[^/]+/;
// if relative url in files found - try to make it absolute
if (data.url) {
let m = data.url.match(regex);
if (data.image && data.image[0] == ‘/’) {
data.image = m[0] + data.image;
}

if (data.favicon && data.favicon[0] == '/') {
  data.favicon = m[0] + data.favicon;
}

}

return data;

}

The error im recieveing in Make is “Error: SyntaxError: Invalid or unexpected token”, but it works in their playground, the same code


image

Welcome to the Make community!

1. Screenshots of module fields and filters

Please share screenshots of relevant module fields and filters in question? It would really help other community members to see what you’re looking at.

You can upload images here using the Upload icon in the text editor:
Screenshot_2023-10-07_111039

2. Scenario blueprint

Please export the scenario blueprint file to allow others to view the mappings and settings. At the bottom of the scenario editor, you can click on the three dots to find the Export Blueprint menu item.

Screenshot_2023-08-24_230826
(Note: Exporting your scenario will not include private information or keys to your connections)

Uploading it here will look like this:

blueprint.json (12.3 KB)

3. And most importantly, Input/Output bundles

Please provide the input and output bundles of the modules by running the scenario (or get from the scenario History tab), then click the white speech bubble on the top-right of each module and select “Download input/output bundles”.
Screenshot_2023-10-06_141025

A.

Save each bundle contents in your text editor as a bundle.txt file, and upload it here into this discussion thread.

Uploading them here will look like this:

module-1-input-bundle.txt (12.3 KB)
module-1-output-bundle.txt (12.3 KB)

B.

If you are unable to upload files on this forum, alternatively you can paste the formatted bundles in this manner:

  • Either add three backticks ``` before and after the code, like this:

    ```
    input/output bundle content goes here
    ```

  • Or use the format code button in the editor:
    Screenshot_2023-10-02_191027

Providing the input/output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

Following these steps will allow others to assist you here. Thanks!

2 Likes

Remove the comments/markup from your code and it should work.