How to extract exact url of a insta profile picture using cheerio?

I m making a insta profile image extracter using cheerio now the problem is it is not fetching the exact size of a image like when i inspected a image page on insta in the chrome developer tools i was able to see full and hd image in a new tab now in my code i my code it is just fetching the 320×320 image here is the example of image url that my code fetch’s.
https://instagram.fkhi25-1.fna.fbcdn.net/v/t51.2885-19/437937765_2168167833531480_2736325614077431115_n.jpg?stp=dst-jpg_s320x320_tt6&_nc_ht=instagram.fkhi25-1.fna.fbcdn.net&_nc_cat=1&_nc_oc=Q6cZ2AHo6DXdTchbD3TRojEikoLin3hj-b8oxc_jMqzHut5s3KusCglE2AxiS0ZSFDdNx5Q&_nc_ohc=QONOOjHPgZ4Q7kNvgGD_IME&_nc_gid=efc7a41b006a4b03b7f8317f333ad110&edm=AOQ1c0wBAAAA&ccb=7-5&oh=00_AYDr_14nnokGjuhvgNMDdakPa6lbRc53lreWp_SeztiLww&oe=67739EAE&_nc_sid=8b3546

And here is the actual image url.
https://instagram.fkhi25-1.fna.fbcdn.net/v/t51.2885-19/437937765_2168167833531480_2736325614077431115_n.jpg?_nc_ht=instagram.fkhi25-1.fna.fbcdn.net&_nc_cat=1&_nc_oc=Q6cZ2AHEtqqQYzAKMOwbn3lvbGDq4e3kKNxeS347vWwQbL1ZY9sZvSeG9wRBc5tjEOJDC0A&_nc_ohc=QONOOjHPgZ4Q7kNvgE7pwyH&_nc_gid=a5163103d3184dcd86d160c27039f1c3&edm=APoiHPcBAAAA&ccb=7-5&oh=00_AYDCzN-s9DKjtt-08LZKqTOOTToI2ODjAgt7p16FRDf7aw&oe=67739EAE&_nc_sid=22de04

You will know the difference when you open both of them.

Sorry for the bad code i m a bit begineer.

const express = require('express');
const router = express.Router();
const app = express();
const axios = require('axios');
const path = require('path');
const fs = require('fs');
const cheerio = require('cheerio');
const { InstaClient } = require('insta-fetcher');
require('dotenv').config();

const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
// Define the route for rendering mp3.ejs
router.get('/mp3', (req, res) => { 
    res.render('mp3');
});
app.use(express.urlencoded({ extended: true }));
const puppeteer = require("puppeteer");

// Connect to Instagram
// API endpoint to fetch profile picture
// API endpoint to fetch profile picture using Puppeteer
const bodyParser = require('body-parser');
app.use(bodyParser.json());

function extractUsername(url) {
  const matches = url.match(/instagram.com/([A-Za-z0-9_.]+)/);
  return matches ? matches[1] : null;
}

router.post('/api/get-profile-pic', async (req, res) => {
  try {
      const { profileUrl } = req.body;
      console.log('Received request for:', profileUrl);

      if (!profileUrl) {
          return res.status(400).json({ error: 'Profile URL is required' });
      }

      // Extract username from URL
      const username = extractUsername(profileUrl);
      if (!username) {
          return res.status(400).json({ error: 'Invalid Instagram URL' });
      }

      // Use Instagram's public API
      const response = await axios.get(`https://www.instagram.com/api/v1/users/web_profile_info/?username=${username}`, {
          headers: {
              'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
              'Accept': 'application/json',
              'X-IG-App-ID': '936619743392459',
              'X-Requested-With': 'XMLHttpRequest',
          }
      });

      if (response.data && response.data.data && response.data.data.user) {
          // Attempt to get the HD profile picture
          const profilePicUrl = response.data.data.user.profile_pic_url_hd || response.data.data.user.profile_pic_url;
          
          // Optionally, you can remove the size portion of the URL to ensure it's the full-size picture
          const fullSizePicUrl = profilePicUrl.replace(/_s[0-9]+x[0-9]+/, ''); // Removes the _s320x320 part from the URL if it exists

          console.log('Found profile picture URL:', fullSizePicUrl);
          res.json({ imageUrl: fullSizePicUrl });
      } else {
          throw new Error('Profile not found');
      }
  } catch (error) {
      console.error('Error details:', error);
      res.status(500).json({
          error: 'Failed to fetch profile picture',
          details: error.message,
      });
  }
});
module.exports = router; 

if some one can help me through this problem that would be appreciated.

New contributor

Ashwin Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật