Created
January 8, 2020 21:10
-
-
Save GianlucaGuarini/54afc7b4ac561fa46903359297084e41 to your computer and use it in GitHub Desktop.
programming like a modern artist
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
;(async function() { | |
// puppeteer boilerplate code | |
const browser = await puppeteer.launch({ | |
args: ['--no-sandbox', '--disable-setuid-sandbox'], | |
// notice the small device size | |
defaultViewport: { | |
width: 375, | |
height: 812 | |
} | |
}) | |
const page = await browser.newPage() | |
// use iPhone UA | |
page.setUserAgent( | |
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1' | |
) | |
// Do login | |
// this is actually in a separate file but I have dumped it here for demo | |
console.log('logging in') | |
await page.goto('https://www.instagram.com/accounts/login/') | |
await page.waitForSelector('form') | |
await page.focus('input[name=username]') | |
await page.keyboard.type(process.env.INSTA_ACCOUNT) | |
await page.focus('input[name=password]') | |
await page.keyboard.type(process.env.INSTA_PASSWORD) | |
console.log('submit form') | |
await page.keyboard.press('Enter') | |
await page.waitForNavigation() | |
try { | |
await page.click('main button') | |
await page.waitForNavigation() | |
} catch (error) { | |
console.log('no need to store login credentials') | |
} | |
)()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment