Create pinterest.js
Browse files- lib/@randydev/pinterest.js +42 -0
lib/@randydev/pinterest.js
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import axios from "axios";
|
2 |
+
import * as cheerio from "cheerio";
|
3 |
+
|
4 |
+
export async function PinterestDownloader(search) {
|
5 |
+
if (!search) {
|
6 |
+
return {
|
7 |
+
status: "False",
|
8 |
+
randydev: { error: "pinterest API" }
|
9 |
+
};
|
10 |
+
}
|
11 |
+
|
12 |
+
const headers = {
|
13 |
+
"authority": "www.pinterest.com",
|
14 |
+
"cache-control": "max-age=0",
|
15 |
+
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
16 |
+
"upgrade-insecure-requests": "1",
|
17 |
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
18 |
+
"sec-gpc": "1",
|
19 |
+
"sec-fetch-site": "same-origin",
|
20 |
+
"sec-fetch-mode": "same-origin",
|
21 |
+
"sec-fetch-dest": "empty",
|
22 |
+
"accept-language": "en-US,en;q=0.9",
|
23 |
+
"cookie": "csrftoken=92c7c57416496066c4cd5a47a2448e28; g_state={\"i_l\":0}; _auth=1; _pinterest_sess=TWc9PSZBME..."
|
24 |
+
};
|
25 |
+
|
26 |
+
const url = `https://www.pinterest.com/search/pins/?q=${encodeURIComponent(search)}&rs=typed&term_meta[]=${encodeURIComponent(search)}|typed`;
|
27 |
+
|
28 |
+
try {
|
29 |
+
const response = await axios.get(url, { headers });
|
30 |
+
const html = response.data;
|
31 |
+
const imageUrls = html.match(/https:\/\/i\.pinimg\.com\/originals\/[^.]+\.jpg/g) || [];
|
32 |
+
return {
|
33 |
+
count: imageUrls.length,
|
34 |
+
data: imageUrls
|
35 |
+
};
|
36 |
+
} catch (error) {
|
37 |
+
return {
|
38 |
+
status: "False",
|
39 |
+
randydev: { error: "An error occurred while fetching data" }
|
40 |
+
};
|
41 |
+
}
|
42 |
+
}
|