I am trying to get my hands on Apify's Actor Metamorph with a very simple example :
const Apify = require('apify');
const request = require('request-promise');
Apify.main(async () => {
const newInput = {
startUrls: [{url: "http://example.org"}],
pageFunction: () => {
const title = await page.title();
console.log(title);
}
};
await Apify.metamorph('apify/web-scraper', newInput);
});
However the run fails with a syntax error :
SyntaxError: await is only valid in async function
How do I pass the async
nature of pageFunction
to the apify/web-scraper
through Metamorph ?
Just put the async
keyword in front of the function:
pageFunction: async () => {
const title = await page.title();
console.log(title);
}