|
import axios from "axios"; |
|
import * as cheerio from "cheerio"; |
|
|
|
export async function PinterestDownloader(search) { |
|
if (!search) { |
|
return { |
|
status: "False", |
|
randydev: { error: "pinterest API" } |
|
}; |
|
} |
|
|
|
const headers = { |
|
"authority": "www.pinterest.com", |
|
"cache-control": "max-age=0", |
|
"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", |
|
"upgrade-insecure-requests": "1", |
|
"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", |
|
"sec-gpc": "1", |
|
"sec-fetch-site": "same-origin", |
|
"sec-fetch-mode": "same-origin", |
|
"sec-fetch-dest": "empty", |
|
"accept-language": "en-US,en;q=0.9", |
|
"cookie": "csrftoken=92c7c57416496066c4cd5a47a2448e28; g_state={\"i_l\":0}; _auth=1; _pinterest_sess=TWc9PSZBME..." |
|
}; |
|
|
|
const url = `https://www.pinterest.com/search/pins/?q=${encodeURIComponent(search)}&rs=typed&term_meta[]=${encodeURIComponent(search)}|typed`; |
|
|
|
try { |
|
const response = await axios.get(url, { headers }); |
|
const html = response.data; |
|
const imageUrls = html.match(/https:\/\/i\.pinimg\.com\/originals\/[^.]+\.jpg/g) || []; |
|
return { |
|
count: imageUrls.length, |
|
data: imageUrls |
|
}; |
|
} catch (error) { |
|
return { |
|
status: "False", |
|
randydev: { error: "An error occurred while fetching data" } |
|
}; |
|
} |
|
} |