-
Notifications
You must be signed in to change notification settings - Fork 8
/
phan.js
50 lines (37 loc) · 1.31 KB
/
phan.js
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
var page = require('webpage').create();
page.viewportSize = { width:1024 , height: 600 };
page.settings.userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.82 Safari/537.36';
page.open('https:/instagram.com/accounts/login/', function() {
var ig = page.evaluate(function() {
function getCoords(box) {
return {
x: box.left,
y: box.top
};
}
function getPosition(type, name) {
// find fields to fill
var input = document.getElementsByTagName(type);
for(var i = 0; i < input.length; i++) {
if(name && input[i].name == name) return getCoords(input[i].getBoundingClientRect());
else if(!name && input[i].className) return getCoords(input[i].getBoundingClientRect()); // this is for login button
}
}
return {
user: getPosition('input', 'username'),
pass: getPosition('input', 'password'),
login: getPosition('button')
};
});
// fill in data and press login
page.sendEvent('click',ig.user.x, ig.user.y);
page.sendEvent('keypress', 'myusername');
page.sendEvent('click',ig.pass.x, ig.pass.y);
page.sendEvent('keypress', 'mypassword');
page.sendEvent('click',ig.login.x, ig.login.y);
// wait for response
setTimeout(function() {
page.render('insta.png');
phantom.exit();
}, 5000);
});