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

instagram-searchtags

v2.0.9

Published

Instagram scraper searching tags

Downloads

28

Readme

Instagram search hashtags

npm version GitHub release npm

Why this package?

The API of instagram limits search for hashtags by authorized user tags only with a limit of 20 images. The API also has a rate limit.

Before we could easily fetch all tags with the endpoints /explore/tags. Instagram recently authorized these endpoints. Therefore it will not work for third party apps.

Instead of using the API, this package scrapes data without any limits. It uses phantomjs to get the data.

Install

npm install instagram-searchtags --save

Usage

Add the environment variable DEBUG=instagramsearchtags to run with debug information in the console, example:

DEBUG=instagramsearchtags node some-script.js

Basic example: fetching 10 hashtag #dog nodes

const InstagramSearchTags = require('instagram-searchtags')

// Create instance with your credentials
const searchTags = new InstagramSearchTags({
  username: 'instagram-username-or-email',
  password: 'xxx',
})

// Login Instagram with credentials
searchTags.login()
  .then(() => {

    // Create #dog tag
    const tag = searchTags.createTag('dog')

    // Fetch 10 latest nodes
    return tag.fetchNodes(10)

  })
  .then((nodes) => {

    // ... do something cool with nodes

    // close connection
    searchTags.close()

  })
  .catch((err) => {

    // close connection
    searchTags.close()

    console.error(`Error: ${err.message}`)

  })

See other examples:

Let's break it down in some basic steps:

  1. Create an instance of InstagramSearchTags with your credentials
  2. Login with these credentials with the method login(), this method returns a Promise.
  3. After you've successfully logged in, you will be able to create tags with the method createTag(). This method returns a Tag instance.
  4. With the Tag instance you can invoke several fetch methods, such as fetchNodes() which returns a Promise with the resolved nodes.
  5. Close the PhantomJS connection with the close() method.

Documentation

InstagramSearchTags Class

The InstagramSearchTags Class is the main class to construct and destruct searching Instagram hashtags.

  • Create connection:

    const searchTags = new InstagramSearchTags({
      username: 'instagram-username-or-email',
      password: 'xxx',
    })
  • Create Tag instance:

    Method structure (pseudo code): InstagramSearchTags.createTag(:String): Tag

    const dogTag = searchTags.createTag('dog')
  • Close connection:

    Method structure (pseudo code): InstagramSearchTags.close(): Promise.<void>

    await searchTags.close()

Tag Class

The Tag Class is used to create tags and fetch data from it.

  • Fetching single page:

    Method structure (pseudo code): Tag.fetchPage(maxId:String): Promise.<Page>

    This method fetch a single page object including top_posts etc. The parameter maxId is the hash for the page to fetch (this is optional).

    const page = await tag.fetchPage()
  • Fetching next page:

    Method structure (pseudo code): Tag.fetchNextPage(): Promise.<Page>

    This method fetch the next page. Useful for manually iterate through pages

    const page = await tag.fetchPage()
    
    if (page.hasNextPage()) {
      const nextPage = await tag.fetchNextPage()
    }
  • Fetching nodes:

    Method structure (pseudo code): Tag.fetchNodes(maxNodes:Number): Promise.<Array>

    This method fetch media nodes with a maximum. Internal it uses fetchPage and fetchNextPage recursively till the nodes Array is constructed.

    const nodes = await tag.fetchNodes(20)
  • Download thumbnail images:

    Method structure (pseudo code): Tag.downloadNodeThumbnailImages(destinationDirectory:String, maxNodes:Number): Promise.<void>

    This method fetch media nodes with a maximum maxNodes and download image to destinationDirectory. It uses the property thumbnail_src from a single node.

    const nodes = await tag.downloadNodeThumbnailImages('./images', 20)
  • Download display images:

    Method structure (pseudo code): Tag.downloadNodeDisplayImages(destinationDirectory:String, maxNodes:Number): Promise.<void>

    This method fetch media nodes with a maximum maxNodes and download image to destinationDirectory. It uses the property display_src from a single node.

    const nodes = await tag.downloadNodeDisplayImages('./images', 20)
  • Get the total amount of media nodes found for given tag query.:

    Method structure (pseudo code): Tag.getTotalCount(): Promise.<Number>

    const totalCount = await tag.getTotalCount()
  • Get state if has next page:

    Method structure (pseudo code): Tag.hasNextPage(): Boolean

    const hasNextPage = tag.hasNextPage()

Page Class

The Page Class is generated by Tag instances. It provide an interface of fetching data. This class represent a single Instagram query /explore/tags/${tag}?__a=1 entry.

  • Get state if has next page:

    Method structure (pseudo code): page.hasNextPage(): Boolean

    const hasNextPage = page.hasNextPage()
  • Get next page hash (maxId):

    Method structure (pseudo code): page.getNextPageMaxId(): String|Boolean.<false>

    Get the hash maxId for the next page. Returns false when there is no next page found.

    const maxId = page.getNextPageMaxId()
  • Get page nodes:

    Method structure (pseudo code): page.getNodes(): Array

    Returns all media nodes of page

    const nodes = page.getNodes()
  • Get total result count of tag:

    Method structure (pseudo code): page.getTotalCount(): Number

    The result of this method is the same as for Tag.prototype.getTotalCount()

    const totalNodeCount = page.getTotalCount()