```
import { PuppeteerCrawler } from 'crawlee'
import fs from 'fs'

// Create a write stream
const logStream = fs.createWriteStream('output.log', { flags: 'a' })

const crawler = new PuppeteerCrawler({
  maxConcurrency: 2,
  launchContext: {
    launchOptions: {
      headless: true
    }
  },
  async requestHandler({ request, page }) {
    logStream.write(`Crawling ${request.url}\n`)

    try {
      await Promise.all([
        page.goto(request.url, { timeout: 60000 }),
        page.waitForNavigation({ waitUntil: 'networkidle0', timeout: 60000 })
      ])
    } catch (error) {
      logStream.write(`Navigation failed on ${request.url}, skipping this page.\n`)
      return
    }

    // Extract links using the provided selector
    let links
    try {
      links = await page.$$eval('#refazerLista div.textoInstituicao2 a', (anchors) =>
        anchors.map((anchor) => anchor.href)
      )
      logStream.write(`Links on ${request.url}: ${links.join(', ')}`)
    } catch (error) {
      logStream.write(`Failed to extract links on ${request.url}, skipping this page.\n`)
      return
    }

    // If it's not one of the original pages, assume it's a link from one of them and extract PDF links
    const pdfLinks = await page.$$eval('div.linkArquivo div.campoLinkArquivo a[href$=".pdf"]', (anchors) =>
      anchors.map((anchor) => anchor.href)
    )
    logStream.write(`PDF Links on ${request.url}: ${pdfLinks.join(', ')}`)

    await page.close()
  }
})

// Crawl only the two original pages
const pages = [
  'https://www.concursosfcc.com.br/concursoAndamento.html',
  'https://www.concursosfcc.com.br/concursoOutraSituacao.html'
]

await crawler.run(pages)

// Don't forget to close the stream when you're done
logStream.end()
```
