Skip to content

Instantly share code, notes, and snippets.

@GianlucaGuarini
Created January 8, 2020 21:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GianlucaGuarini/54afc7b4ac561fa46903359297084e41 to your computer and use it in GitHub Desktop.
Save GianlucaGuarini/54afc7b4ac561fa46903359297084e41 to your computer and use it in GitHub Desktop.
programming like a modern artist
;(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