|
| 1 | +.. meta:: |
| 2 | + :description: |
| 3 | + Documentation of Instaloader module, a powerful and intuitive |
| 4 | + Python library to download Instagram media and metadata. |
| 5 | + |
| 6 | +.. _python-module-instaloader: |
| 7 | + |
| 8 | +Python Module :mod:`instaloader` |
| 9 | +-------------------------------- |
| 10 | + |
| 11 | +.. module:: instaloader |
| 12 | + |
| 13 | +.. highlight:: python |
| 14 | + |
| 15 | +Instaloader exposes its internally used methods and structures as a Python |
| 16 | +module, making it a powerful and intuitive Python API for Instagram, |
| 17 | +allowing to further customize obtaining media and metadata. |
| 18 | + |
| 19 | +Start with getting an instance of :class:`Instaloader`:: |
| 20 | + |
| 21 | + import instaloader |
| 22 | + |
| 23 | + # Get instance |
| 24 | + L = instaloader.Instaloader() |
| 25 | + |
| 26 | + # Optionally, login or load session |
| 27 | + L.login(USER, PASSWORD) # (login) |
| 28 | + L.interactive_login(USER) # (ask password on terminal) |
| 29 | + L.load_session_from_file(USER) # (load session created w/ |
| 30 | + # `instaloader -l USERNAME`) |
| 31 | + |
| 32 | +:mod:`instaloader` provides the :class:`Post` structure, which represents a |
| 33 | +picture, video or sidecar (set of multiple pictures/videos) posted in a user's |
| 34 | +profile. :class:`Instaloader` provides methods to iterate over Posts from a |
| 35 | +certain source:: |
| 36 | + |
| 37 | + for post in instaloader.Hashtag.from_name(L.context, 'cat').get_posts(): |
| 38 | + # post is an instance of instaloader.Post |
| 39 | + L.download_post(post, target='#cat') |
| 40 | + |
| 41 | +:class:`Post` instances can be created with: |
| 42 | + |
| 43 | +- :func:`Post.from_shortcode` |
| 44 | + Use a Post shortcode (part of the Post URL, |
| 45 | + ``https://www.instagram.com/p/SHORTCODE/``) to create a Post |
| 46 | + object:: |
| 47 | + |
| 48 | + post = Post.from_shortcode(L.context, SHORTCODE) |
| 49 | + |
| 50 | +- :meth:`Profile.get_posts` |
| 51 | + All media of a :class:`Profile`. |
| 52 | + |
| 53 | +- :meth:`Profile.get_saved_posts` |
| 54 | + Media that the user marked as saved (:class:`Profile` must be own profile |
| 55 | + for this to work) |
| 56 | + |
| 57 | +- :meth:`Instaloader.get_feed_posts` |
| 58 | + Media in the user's feed. |
| 59 | + |
| 60 | +- :meth:`Instaloader.get_explore_posts` |
| 61 | + Media that is suggested by Instagram to explore. |
| 62 | + |
| 63 | +- :meth:`Hashtag.get_posts` |
| 64 | + Media associated with given hashtag. |
| 65 | + |
| 66 | +With the :class:`Profile` class, Instaloader also makes it easy to access |
| 67 | +metadata of a Profile. :class:`Profile` instances can be created with: |
| 68 | + |
| 69 | +- :meth:`Profile.from_username`:: |
| 70 | + |
| 71 | + profile = Profile.from_username(L.context, USERNAME) |
| 72 | + |
| 73 | +- :meth:`Profile.from_id` |
| 74 | + given its User ID. This allows to easily lookup a Profile's username given |
| 75 | + its ID:: |
| 76 | + |
| 77 | + Profile.from_id(L.context, USERID).username |
| 78 | + |
| 79 | +- :meth:`Profile.get_followees` |
| 80 | + Profiles that are followed by given user. |
| 81 | + |
| 82 | +- :meth:`Profile.get_followers` |
| 83 | + Profiles that follow given user. |
| 84 | + |
| 85 | +- :attr:`Post.owner_profile`, :attr:`Story.owner_profile`, :attr:`StoryItem.owner_profile` |
| 86 | + Owner profile of particular object. |
| 87 | + |
| 88 | +- :meth:`Post.get_likes` |
| 89 | + Profiles that liked a given :class:`Post` |
| 90 | + |
| 91 | +- :attr:`PostComment.owner` |
| 92 | + Profile of a Post comment. |
| 93 | + |
| 94 | +For a list of a few code examples that use the Instaloader module, see |
| 95 | +:ref:`codesnippets`. |
| 96 | + |
| 97 | +The reference of the classes and functions provided by the :mod:`instaloader` module is |
| 98 | +divided into the following subsections: |
| 99 | + |
| 100 | +.. toctree:: |
| 101 | + :maxdepth: 2 |
| 102 | + |
| 103 | + module/instaloader |
| 104 | + module/structures |
| 105 | + module/nodeiterator |
| 106 | + module/instaloadercontext |
| 107 | + module/exceptions |
0 commit comments