Created
June 16, 2021 13:28
-
-
Save Tuarisa/9c04101631cf7812c3e7ae51e1779cda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Require puppeteer | |
const puppeteer = require('puppeteer'); | |
(async () => { | |
// Create an instance of the chrome browser | |
// But disable headless mode ! | |
const browser = await puppeteer.launch({ | |
headless: false | |
}); | |
// Create a new page | |
const page = await browser.newPage(); | |
// Configure the navigation timeout | |
await page.setDefaultNavigationTimeout(0); | |
await page.setRequestInterception(true); | |
page.on('request', request => { | |
// console.log(request); | |
request.continue(); | |
}); | |
page.on('requestfinished', async (request) => { | |
try { | |
const response = await request.response(); | |
const url = response.url(); | |
if (url.indexOf('api-partner')> -1) { | |
const json = await response.json(); | |
console.log(JSON.stringify(json, null, 2)) | |
} | |
} catch(e) { | |
// | |
} | |
}); | |
// Navigate to some website e.g Our Code World | |
try { | |
await page.goto('https://open.spotify.com/track/5VNcKdmfAAsfbxbuo1Y7Vl?si=1303ef0370f3423e', { waitUntil: 'networkidle0' }); | |
console.log('done'); | |
} | |
catch(e) { | |
console.log(e); | |
} | |
finally { | |
await browser.close(); | |
} | |
// Do your stuff | |
// ... | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment