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);
}
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() // <--
}