Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
basic webscraper not exiting async function

When I run this function I get the expected result via console.log, but the function is not exited. Why is that the case?

const puppeteer = require('puppeteer');

async function scrape(url) {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    const target = await page.goto(url);
    const waiting = await page.waitForXPath('XPATH...');
    const [el] = await page.$x('XPATH...');
    const txt = await el.getProperty('textContent');

    const rawTxt  = txt.jsonValue();
    console.log(rawTxt);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try to close Puppeteer when you complete your task.

// ... your code
browser.close()
const puppeteer = require('puppeteer');

async function scrape(url) {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    const target = await page.goto(url);
    const waiting = await page.waitForXPath('XPATH...');
    const [el] = await page.$x('XPATH...');
    const txt = await el.getProperty('textContent');

    const rawTxt  = txt.jsonValue();
    console.log(rawTxt);

    browser.close() // <--
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!