npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aduptive/instagram-scraper

v1.0.0

Published

Modern TypeScript library for collecting public Instagram content with smart delays, mobile-first approach, and media support

Downloads

71

Readme

Instagram Scraper

A lightweight TypeScript library for scraping public Instagram profiles without authentication. This tool allows you to fetch recent posts from any public Instagram profile while respecting rate limits and implementing best practices for web scraping.

Features

  • 🚫 No authentication required
  • 📱 Mobile-first approach for better reliability
  • 🔄 Random delays and mobile user agents rotation
  • ⚡ Lightweight and easy to use
  • 📦 Written in TypeScript with full type support
  • 🛡️ Built-in rate limiting and error handling
  • 💾 JSON export functionality

Installation

npm install @aduptive/instagram-scraper

Usage

Basic Usage

import { InstagramScraper } from '@aduptive/instagram-scraper';

async function main() {
  const scraper = new InstagramScraper();
  
  try {
    // Get the last 20 posts from a public profile
    const results = await scraper.getPosts('instagram', 20);
    
    if (results.success && results.posts) {
      console.log(`Successfully collected ${results.posts.length} posts`);
      // Save to JSON file
      await scraper.saveToJson(results);
    } else {
      console.error('Error:', results.error);
    }
  } catch (error) {
    console.error('Critical error:', error);
  }
}

main();

With Configuration

const scraper = new InstagramScraper({
  maxRetries: 3,
  minDelay: 2000,
  maxDelay: 5000,
  timeout: 10000,
  rateLimitPerMinute: 20
});

Multiple Profiles

async function scrapeMultipleProfiles(usernames: string[]) {
  const scraper = new InstagramScraper();
  
  for (const username of usernames) {
    try {
      // Random delay between requests (2-5 seconds)
      await new Promise(resolve => 
        setTimeout(resolve, 2000 + Math.random() * 3000)
      );
      
      const results = await scraper.getPosts(username, 20);
      if (results.success) {
        console.log(`${username}: ${results.posts?.length} posts collected`);
      } else {
        console.log(`${username}: ${results.error}`);
      }
    } catch (error) {
      console.error(`Error collecting ${username}:`, error);
    }
  }
}

Error Handling

import { InstagramScraper, ScrapeError } from '@aduptive/instagram-scraper';

try {
  const results = await scraper.getPosts('username');
  if (!results.success) {
    console.error('Failed:', results.error);
    return;
  }
  // Handle success...
} catch (error) {
  if (error instanceof ScrapeError) {
    console.error(`Scraping error: ${error.message} (${error.code})`);
  } else {
    console.error('Unknown error:', error);
  }
}

Configuration Options

interface ScraperConfig {
  maxRetries?: number;      // Maximum number of retry attempts (default: 3)
  minDelay?: number;        // Minimum delay between requests in ms (default: 1000)
  maxDelay?: number;        // Maximum delay between requests in ms (default: 3000)
  timeout?: number;         // Request timeout in ms (default: 10000)
  rateLimitPerMinute?: number; // Maximum requests per minute (default: 30)
}

Best Practices

  1. Rate Limiting: The tool implements built-in delays, but you should still be mindful of Instagram's rate limits
  2. Error Handling: Always implement proper error handling as shown in the examples
  3. Delays: Use appropriate delays between requests to avoid being blocked
  4. User Agents: The tool rotates mobile user agents automatically

Known Limitations

  • Works only with public Instagram profiles
  • Limited to basic post information available on the profile page
  • Instagram may change their HTML structure at any time
  • Rate limiting may apply

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This tool is provided for educational purposes only. Make sure to read and comply with Instagram's terms of service and robots.txt file. The authors are not responsible for any misuse of this tool.

Support

If you found this project helpful, please consider giving it a ⭐️!