Skip to content

Instantly share code, notes, and snippets.

@pirmax
Created Feb 11, 2019
Embed
What would you like to do?
Twitter : envoyer un message privé aux nouveaux followers sans API avec Puppeteer
const puppeteer = require('puppeteer');
const schedule = require('node-schedule');
(async () => {
const recipients = [];
const browser = await puppeteer.launch({
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox'
]
});
const page = await browser.newPage();
page.emulate({
name: 'Desktop 1920x1080',
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
viewport: {
width: 1920,
height: 1080
}
});
await page.setCookie({
name: 'auth_token',
value: 'rtc22r958xxxxxxxxxxxxxxxx8ab20241',
domain: '.twitter.com',
path: '/',
expires: (new Date().getTime() + 86409000),
httpOnly: true,
secure: true
});
schedule.scheduleJob('*/10 * * * *', async () => {
await page.goto('https://twitter.com/pirmax/followers', {waitUntil: 'networkidle2'});
const users = await page.evaluate(
() => Array.from(document.body.querySelectorAll('div[data-item-type="user"] > div.ProfileCard'), (element) => {
return {
name: element.getAttribute('data-screen-name'),
id: element.getAttribute('data-user-id')
}
})
);
for (const user of users) {
if (recipients.indexOf(user.id) <= -1) {
recipients.push(user.id);
console.log(user.name, user.id);
await page.goto('https://twitter.com/messages/compose?text=' + encodeURI('Hey @' + user.name + ', merci pour le follow, vous pouvez lire nos articles sur @YubiGeek ! https://yubigeek.rocketcard.io/') + '&recipient_id=' + user.id);
await page.waitFor(Math.floor((Math.random() * 15000) + 5000));
await page.click('form > div.DMComposer-send > button');
await page.waitFor(Math.floor((Math.random() * 10000) + 1000));
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment