I'm writing a web scraper to verify dates of sports events. One website is not showing sport event url on the listing, but instead link like: www.domain.com/redirectsystem/id12345 etc, once clicked new tab is being opened with the event website. What I want to achieve is to get url of this website opened in new tab.
I have managed to click the link with puppeteer, website is being opened in new tab but I don't know how to get the url information
const browser = await puppeteer.launch({
headless: false,
'args' : [
'--no-sandbox',
'--disable-setuid-sandbox'
]
});
const newPagePromise = new Promise(x => browser.once('targetcreated', target => x(target.page())));
await page.click('span.link-hightlight');
const newPage = await newPagePromise;
const url = await newPage.url() // this is not working
console.log(url)
You can simply use page.url() to get the page URL
const url = await page.url();
console.log(url);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With