0

POSTクローラーを開始するエンドポイントを備えた高速サーバーがあります。クローラーが完了すると、サーバー全体がシャットダウンされます。私は何か間違ったことをしていますか?どうすればそれを防ぐことができますか?

プロジェクトは次のようになります。

// server.js
const express = require('express')
const bodyParser = require('body-parser')
const startSearch = require('./crawler.js')

const app = express()

app.use(bodyParser.json())

app.post('/crawl', async (req, res) => {
  const { foo, bar } = req.body

  startSearch({ foo, bar })
  res.end()
})

app.listen(PORT, () => console.log(`listening on port ${PORT}`))

// crawler.js
const Apify = require('apify')

const startSearch = ({ foo, bar }) => {
  Apify.main(async () => {
    const sources = [{
      url: 'https://path_to_website.com',
      userData: { foo, bar }
    }]
    const requestList = await Apify.openRequestList(null, sources)

    const crawler = new Apify.PuppeteerCrawler({
      requestList,
      handlePageFunction: async ({ request, page }) => {
          // do things using puppeteer
        }
      }
    })

    await crawler.run()
  })
}
4

1 に答える 1

0

の使用は避けてApify.main()ください。詳細については、Google Cloud Functions で Apify を使用する方法を参照してください。

(返事を送ったつもりがコメントだけだったようです)

于 2020-01-13T19:16:11.710 に答える