-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpinterest.js
More file actions
109 lines (99 loc) · 4.23 KB
/
pinterest.js
File metadata and controls
109 lines (99 loc) · 4.23 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*──────────────────────────────────────────────────────────
* 🧩 NeoBot - Powered by NeoShiroko Labs
*──────────────────────────────────────────────────────────
* 🌐 Website : https://www.neolabsofficial.my.id
* 💬 WhatsApp : https://s.id/contact-zass
* 📺 YouTube : https://www.youtube.com/@ZassOnee
* 📡 Panel Murah : pteroku-desu.zass.cloud
*
* [ ! ] Jangan Hapus Wm Bggg
*──────────── © 2025 Zass Onee. All rights reserved.───────────────────
*/
const axios = require('axios')
async function getCookies() {
try {
const response = await axios.get('https://www.pinterest.com/csrf_error/');
const setCookieHeaders = response.headers['set-cookie'];
if (setCookieHeaders) {
const cookies = setCookieHeaders.map(cookieString => {
const cookieParts = cookieString.split(';');
const cookieKeyValue = cookieParts[0].trim();
return cookieKeyValue;
});
return cookies.join('; ');
} else {
console.warn('No set-cookie headers found in the response.');
return null;
}
} catch (error) {
console.error('Error fetching cookies:', error);
return null;
}
}
async function pinterest(query) {
try {
const cookies = await getCookies();
if (!cookies) {
console.log('Failed to retrieve cookies. Exiting.');
return;
}
const url = 'https://www.pinterest.com/resource/BaseSearchResource/get/';
const params = {
source_url: `/search/pins/?q=${query}`, // Use encodedQuery here
data: JSON.stringify({
"options": {
"isPrefetch": false,
"query": query,
"scope": "pins",
"no_fetch_context_on_resource": false
},
"context": {}
}),
_: Date.now()
};
const headers = {
'accept': 'application/json, text/javascript, */*, q=0.01',
'accept-encoding': 'gzip, deflate',
'accept-language': 'en-US,en;q=0.9',
'cookie': cookies,
'dnt': '1',
'referer': 'https://www.pinterest.com/',
'sec-ch-ua': '"Not(A:Brand";v="99", "Microsoft Edge";v="133", "Chromium";v="133"',
'sec-ch-ua-full-version-list': '"Not(A:Brand";v="99.0.0.0", "Microsoft Edge";v="133.0.3065.92", "Chromium";v="133.0.6943.142"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-model': '""',
'sec-ch-ua-platform': '"Windows"',
'sec-ch-ua-platform-version': '"10.0.0"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0',
'x-app-version': 'c056fb7',
'x-pinterest-appstate': 'active',
'x-pinterest-pws-handler': 'www/[username]/[slug].js',
'x-pinterest-source-url': '/hargr003/cat-pictures/',
'x-requested-with': 'XMLHttpRequest'
};
const { data } = await axios.get(url, {
headers: headers,
params: params
})
const container = [];
const results = data.resource_response.data.results.filter((v) => v.images?.orig);
results.forEach((result) => {
container.push({
upload_by: result.pinner.username,
fullname: result.pinner.full_name,
followers: result.pinner.follower_count,
caption: result.grid_title,
image: result.images.orig.url,
source: "https://id.pinterest.com/pin/" + result.id,
});
});
return container;
} catch (error) {
console.log(error);
return [];
}
}
module.exports = pinterest