您可以使用 puppeteer 加载该动态页面/应用程序并加载它的 HTML 并将内容保存到 HTML 文件中。然后,如果 Google bot 抓取工具访问您的网站,您可以通过 robots.txt 文件要求他们抓取此 HTML 文件。
您可以在每次想要运行时运行此 puppeteer 脚本。也许您可以使用cron
自动运行此脚本。
像这样的东西:
const puppeteer = require ('puppeteer')
const CronJob = require ('cron').CronJob
const fs = require ('fs-extra')
const crontask = '0 */1 * * *' // This will run script every hour
const urlDynamic = 'https://www.example.com' // Change this to your dynamic url
const staticFile = 'statichtml.html'
;(async () => {
const browser = await puppeteer.launch ({
headless: true,
devtools: false
})
const [page] = await browser.pages ()
const autorun = async () => {
const open = await page.goto ( urlDynamic, { waitUntil: 'networkidle2', timeout: 0 } )
const html = await page.content ()
const save = await fs.writeFile ( staticFile, html )
}
const job = new CronJob(crontask, async () => {
autorun ()
})
job.start()
})