0.0.2 • Published 4 years ago

polypus v0.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

Polypus: Headless Instagram Bot & Scraper

.. image:: http://opensource.box.com/badges/active.svg :target: http://opensource.box.com/badges

.. contents:: :depth: 2 :local:

Installing

.. code-block:: console

npm install polypus

How It Works

Polypus is mainly built around a headless Chrome Node.js API, Puppeteer <https://github.com/puppeteer/puppeteer>_ dependency.

As a result, it can grab out-of-the-box information not otherwise provided by the Instagram GraphQL API, such as accounts related to a provided username.

Polypus also acts as an undetectable Instagram bot that can automate dull tasks, such as following accounts or direct messaging to a specific user.

Quick Usage

A code snippet that uses Polypus' Scraper <https://github.com/pmdy/instagram-bot#class-scraper> class object to get related accounts given the username, @pewdiepie <https://instagram.com/pewdiepie>.

.. code-block:: javascript

var Polypus = require('polypus');

(async function main() {
    const account = {
        username: process.env['username'],
        password: process.env['password'],
    };

    const scraper = new Polypus.Scraper(account);
    await scraper.login();

    const accounts = await scraper.getRelatedAccounts('pewdiepie', 5);
    console.log(accounts);

    await scraper.logout();
})();

// [
//     'minecraft',
//     'pewdiepie.memes1',
//     'itsmarziapie',
//     'pewdiepie_memepage',
//     'pewdiepie_exe'
// ]

API

class: Scraper

.. code-block:: javascript

    const scraper = new Polypus.Scraper(account);

**login()**

This methods launches a headless Chrome browser and logs the scraper in the provided Instagram account. 

..

        **NOTE** The ``login()`` method is required in order to access most methods in the ``Scraper`` class.

**logout()**

This method logs the scraper out of the provided Instagram account and closes the headless Chrome browser.

**getRelatedAccounts(username, limit)**

* username: <`string <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type>`_>
* limit: <`number <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type>`_>
* returns: <`Promise <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise>`_ <`string[] <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type>`_>> Promise resolves an array of strings that represents all (or up to the limit) accounts related to the given username. Promise is rejected if Scraper does not find a section for related accounts.

**getUserData(username)**

* username: <`string <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type>`_>
* returns: <`Promise <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise>`_ <`User <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type>`_>> Promise resolves the User object.

class: Bot

.. code-block:: javascript

const bot = new Polypus.Bot(account);

Copyright and License

::

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the Licens