Back

Pinterest Download Scrape

68 views
nefu Code by: @nefu

Description

Scrape pinterest downloader, base url : https://www.savepin.app

Features

Code (javascript)

pinterest.js
const axios = require('axios');
const cheerio = require('cheerio');
const url = require('url');

async function PinDL(pinterestUrl) {
    if (!pinterestUrl) {
        return { 
            success: false, 
            error: "Pinterest URL was not provided." 
        };
    }

    const targetUrl = `https://www.savepin.app/pinterest/download.php?url=${encodeURIComponent(pinterestUrl)}`;
    
    try {
        const { data } = await axios.get(targetUrl, {
            headers: {
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'
            }
        });

        const $ = cheerio.load(data);

        const title = $('.table-container h1').text().trim();
        const thumbnailUrl = $('.image-container img').attr('src');
        
        if (!title && !thumbnailUrl) {
            throw new Error("Could not find title or thumbnail. The page structure may have changed or the URL is invalid.");
        }

        const downloads = [];
        $('.table-container tbody tr').each((i, elem) => {
            const quality = $(elem).find('td').eq(0).text().trim();
            const format = $(elem).find('td').eq(1).text().trim();
            const downloadLink = $(elem).find('td').eq(2).find('a').attr('href');
            
            if (downloadLink) {
                const parsedLink = new url.URL(downloadLink, 'https://www.savepin.app');
                const finalUrl = parsedLink.searchParams.get('url');

                downloads.push({
                    quality: quality,
                    format: format,
                    url: finalUrl
                });
            }
        });
        
        return {
            success: true,
            title: title,
            thumbnail_preview: thumbnailUrl,
            downloads: downloads
        };

    } catch (error) {
        return { 
            success: false, 
            error: error.message || "Failed to fetch or parse data."
        };
    }
}

module.exports = PinDL;