@apify/n8n-nodes-apify
Version:
n8n nodes for Apify
55 lines • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.scrapeSingleUrl = scrapeSingleUrl;
const n8n_workflow_1 = require("n8n-workflow");
const genericFunctions_1 = require("../../../resources/genericFunctions");
const helpers_1 = require("../../../helpers");
async function scrapeSingleUrl(i) {
var _a;
const url = this.getNodeParameter('url', i);
const crawlerType = this.getNodeParameter('crawlerType', i, 'cheerio');
try {
const input = {
startUrls: [{ url }],
crawlerType,
maxCrawlDepth: 0,
maxCrawlPages: 1,
maxResults: 1,
proxyConfiguration: {
useApifyProxy: true,
},
removeCookieWarnings: true,
saveHtml: true,
saveMarkdown: true,
};
const run = await genericFunctions_1.apiRequest.call(this, {
method: 'POST',
uri: `/v2/acts/${helpers_1.consts.WEB_CONTENT_SCRAPER_ACTOR_ID}/runs`,
body: input,
qs: { waitForFinish: 0 },
});
const runId = ((_a = run === null || run === void 0 ? void 0 : run.data) === null || _a === void 0 ? void 0 : _a.id) || (run === null || run === void 0 ? void 0 : run.id);
if (!runId) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), {
message: 'No run ID returned from actor run',
});
}
const lastRunData = await genericFunctions_1.pollRunStatus.call(this, runId);
const defaultDatasetId = lastRunData === null || lastRunData === void 0 ? void 0 : lastRunData.defaultDatasetId;
if (!defaultDatasetId) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), {
message: 'No dataset ID returned from actor run',
});
}
const [item] = await genericFunctions_1.apiRequest.call(this, {
method: 'GET',
uri: `/v2/datasets/${defaultDatasetId}/items`,
qs: { format: 'json' },
});
return { json: { ...item } };
}
catch (error) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
}
}
//# sourceMappingURL=execute.js.map