-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (71 loc) · 2.32 KB
/
index.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
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
const axios = require("axios").default;
const cheerio = require("cheerio");
const axiosCookieJarSupport = require('axios-cookiejar-support').default;
const tough = require('tough-cookie');
axiosCookieJarSupport(axios);
const cookieJar = new tough.CookieJar();
function getPage() {
axios
.get(
"https://www.10best.com/awards/travel/best-canned-cocktail-company/bravazzi-hard-italian-soda/" ,{withCredentials: true}
)
.then(function (response) {
// handle success
// console.log(response);
const $ = cheerio.load(response.data);
var theOnClick = $("#awardVoteButton").attr("onclick");
var theOnClickPass = theOnClick.split("('").pop().split("')")[0];
let cookies = "";
const cookie1 = response.headers["set-cookie"][0].split(";")[0] + "; ";
const cookie2 = response.headers["set-cookie"][1].split(";")[0] + "; ";
cookieJar.setCookie(cookie1, 'https://www.10best.com/', {"ignoreError":true});
cookieJar.setCookie(cookie2, 'https://www.10best.com/', {"ignoreError":true});
getKey(theOnClickPass, cookies);
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
}
function getKey(theOnClickPass, cookies) {
console.log(theOnClickPass);
console.log(cookies);
axios
.get(
`https://www.10best.com/common/ajax/voteKey.php?key=${theOnClickPass}` ,{jar: cookieJar,withCredentials: true}
)
.then(function (response) {
// handle success
const valKey = encodeURIComponent(response.data.results.validationKey)
console.log(valKey);
vote(theOnClickPass, valKey)
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
}
function vote(theOnClickPass, valKey) {
axios
.get(
`https://www.10best.com/common/ajax/vote.php?voteKey=${theOnClickPass}&validationKey=${valKey}&email=&c=`, {jar: cookieJar,withCredentials: true}
)
.then(function (response) {
// handle success
console.log(response.data.results.errors);
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
}
getPage();