SyntaxError: await is only valid in async function with Apify Metamorph

SyntaxError: await is only valid in async function with Apify Metamorph

我想通过一个非常简单的例子来了解 Apify 的 Actor Metamorph

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);

});

然而 运行 因语法错误而失败:

SyntaxError: await is only valid in async function

如何通过 Metamorph 将 pageFunctionasync 性质传递给 apify/web-scraper

只要在函数前面加上async关键字即可:

pageFunction: async () => {
    const title = await page.title();
    console.log(title);
}