-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
89 lines (73 loc) · 2.31 KB
/
index.js
File metadata and controls
89 lines (73 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const puppeteer = require('puppeteer')
const fs=require('fs')
const https=require('https')
const keys=require('./keys')
const readlineSync=require('readline-sync')
const exec = require('child_process').exec;
const download = (url, destination) => new Promise((resolve,reject)=>
{
const file=fs.createWriteStream(destination)
https.get(url, response=>{
response.pipe(file)
file.on('finish',()=>{
file.close(resolve(true))
})
})
.on('error',error=>{
fs.unlink(destination)
reject(error.message)
})
})
const getCred=async()=>{
let user=keys.user
let pass=keys.pass
if(user.length===0 || pass.length==0)
{
console.log("Set the login credentials in keys.js")
process.exit(1)
}
return [user,pass]
}
const parselink=async(link)=>{
var st=link.split('/').slice(-1)[0]
var name=st.split('?').slice(0)[0]
return name
}
async function start() {
const cred=await getCred()
const user=cred[0]
const pass=cred[1]
var uid=readlineSync.question('enter username to scrap: ')
const browser = await puppeteer.launch({
//headless: false
})
const page = await browser.newPage()
page.setViewport({ width: 1280, height: 800 })
await page.goto('https://www.instagram.com/accounts/login/?source=auth_switcher')
const navigatiomPromise=page.waitForNavigation()
await page.waitForSelector('input[name="username"]');
await page.type('input[name="username"]',user);
await page.type('input[name="password"]',pass);
await page.click('button[type="submit"]');
await navigatiomPromise
await page.waitFor(3000)
await page.goto(`https://www.instagram.com/${uid}`)
//await page.waitFor(3000)
await page.waitForSelector('div img')
const h1 = await page.evaluate(() =>
Array.from(document.querySelectorAll('div img')).map((partner) => partner.src)
);
browser.close();
var mkdir = 'mkdir -p ' + uid;
var child = exec(mkdir, function(err, stdout, stderr) {
if (err) throw err;
});
for(let link of h1){
var fname=await parselink(link)
var location=uid+"/"+fname
download(link,location).then(
console.log(`downloaded ${fname}`)
).catch(error=> console.log(error))
}
}
start();