Created
April 3, 2020 15:12
-
-
Save TomyCesaille/3cd806ac93d1dfef2ce1ce4204519085 to your computer and use it in GitHub Desktop.
puppeteer status scraping on WhatsApp web
This file contains hidden or 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
const puppeteer = require('puppeteer'); | |
// The contact name to track (mind the case). | |
const contactTarget = "Jean-Mich"; | |
(async () => { | |
const browser = await puppeteer.launch({ | |
headless: false, // No headless to scan the QR code. | |
userDataDir: 'data/userdata' // Persist the session. | |
}); | |
const page = await browser.newPage(); | |
await page.goto('https://web.whatsapp.com/'); | |
await page.waitFor(5000); | |
console.log('Awaiting/Checking peering with WhatsApp phone'); | |
await page.waitFor('#side', { timeout: 60000 }).then(() => { // Scan the QR code within the next minute. | |
console.log('Connected !'); | |
}).catch((res) => { | |
console.log('Not connected !', res); | |
return -1; | |
}) | |
await page.waitFor(1000); | |
await page.focus('._2S1VP'); // Focus search input form. | |
await page.keyboard.type(contactTarget, { delay: 100 }); | |
await page.waitFor(6000); | |
let contactElt = (await page.$x(`//*[@class="_25Ooe" and . = "${contactTarget}"]`))[0]; // Select the best result. | |
contactElt.click(); | |
await page.waitFor(5000); | |
let statusElt = await page.$('.O90ur'); | |
let status = await statusElt.evaluate(x => x.textContent); | |
console.log(`Status for ${contactTarget} is '${status}'.`); // `last seen today at 13:15` format. | |
await browser.close(); | |
})(); |
how are u entering the qr code can u plz elaborate
@ritika-rustagi this code saves a screenshot in the file system. You are supposed to open this screenshot and flash the QR code it contains with your Whats-app mobile app.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how are u entering the qr code can u plz elaborate