· 7 years ago · Dec 16, 2018, 01:14 AM
1const request = require('request-promise');
2const requestSt = require('request');
3process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
4const jar = request.jar();
5
6function getHiddenInputValue(body, name) {
7 try {
8 return body
9 .replace('\n', '')
10 .match(new RegExp(`<input type="hidden" name="${name}" value="(.*?)">`, 'igm'))[0]
11 .match(/value="(.*?)">/)[1]
12 .split('"')[0].trim();
13 } catch(e) {
14 return null
15 }
16}
17function randomString(len) {
18 const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
19 let randomString = '';
20 for (let i = 0; i < len; ++i) {
21 const randomPoz = Math.floor(Math.random() * charSet.length);
22 randomString += charSet.substring(randomPoz, randomPoz + 1);
23 }
24 return randomString;
25}
26
27const target_url = 'https://shikimori.org/animes/37991-jojo-no-kimyou-na-bouken-ougon-no-kaze';
28const target_id = 37991;
29const target_type = 'Anime';
30
31
32const user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36';
33
34request.get({
35 jar,
36 url: 'https://shikimori.org/users/sign_up'
37})
38.then(body => {
39 const authenticity_token = getHiddenInputValue(body, 'authenticity_token');
40 let login = randomString(15);
41 let pass = randomString(Math.floor(Math.random() * 5) + 10);
42 console.log(`Login: ${login}\nPassword: ${pass}`);
43 return new Promise((r, rj) => {
44 requestSt.post({
45 url: 'https://shikimori.org/users',
46 jar,
47 headers: {
48 'User-Agent': user_agent
49 },
50 form: {
51 'utf8': "✓",
52 authenticity_token,
53 'user[nickname]': login,
54 'user[email]': login + '@gmail.com',
55 'user[password]': pass
56 },
57 },
58 function (error, response, body) {
59 r(body);
60 });
61 })
62 // Login
63 // return new Promise((r, rj) => {
64 // requestSt.post({
65 // url: 'https://shikimori.org/users/sign_in',
66 // jar,
67 // headers: {
68 // 'User-Agent': user_agent
69 // },
70 // followAllRedirects: true,
71 // form: {
72 // 'utf8': "✓",
73 // authenticity_token,
74 // 'user[nickname]': 'skdkajsldjlasdjl',
75 // 'user[password]': '12345678'
76 // },
77 // },
78 // function (error, response, body) {
79 // r(body);
80 // });
81 // })
82})
83.then(() => {
84 return request.get({
85 url: 'https://shikimori.org',
86 jar,
87 headers: {
88 'User-Agent': user_agent
89 },
90 })
91})
92.then(() => {
93 return request.get({
94 url: target_url,
95 jar,
96 headers: {
97 'User-Agent': user_agent
98 },
99 })
100})
101.then(body => {
102 const user_id = +body.match(/\["\/user-([0-9]+)"\]/igm)[0].match(/\["\/user-([0-9]+)"\]/)[1];
103 return request.post({
104 url: 'https://shikimori.org/api/v2/user_rates',
105 jar,
106 form: {
107 'frontend': 1,
108 'user_rate[user_id]': user_id,
109 'user_rate[target_id]': target_id,
110 'user_rate[target_type]': target_type,
111 'user_rate[status]': 'completed',
112 'user_rate[score]': 10
113 }
114 })
115})
116.then(body => {
117 console.log(body)
118})
119.catch(function (err) {
120 console.log(err);
121});