2017-12-03 15:20:51 +01:00
|
|
|
.. meta::
|
|
|
|
:description:
|
|
|
|
Instaloader can also be used as a powerful and easy-to-use
|
|
|
|
Python API for Instagram, allowing to download media and metadata.
|
|
|
|
|
2017-09-08 10:35:38 +02:00
|
|
|
Python Module :mod:`instaloader`
|
|
|
|
--------------------------------
|
2017-08-25 16:54:36 +02:00
|
|
|
|
2017-09-08 10:35:38 +02:00
|
|
|
.. module:: instaloader
|
2017-08-25 16:54:36 +02:00
|
|
|
|
2017-09-08 10:35:38 +02:00
|
|
|
.. highlight:: python
|
|
|
|
|
2017-11-14 11:18:30 +01:00
|
|
|
Instaloader exposes its internally used methods as a Python module, making it a
|
|
|
|
**powerful and easy-to-use Python API for Instagram**, allowing to further
|
|
|
|
customize obtaining media and metadata.
|
2017-09-08 10:35:38 +02:00
|
|
|
|
2017-11-14 11:18:30 +01:00
|
|
|
Start with getting an instance of :class:`Instaloader`::
|
2017-09-08 10:35:38 +02:00
|
|
|
|
|
|
|
import instaloader
|
|
|
|
|
|
|
|
# Get instance
|
2017-11-14 11:18:30 +01:00
|
|
|
L = instaloader.Instaloader()
|
|
|
|
|
|
|
|
# Optionally, login or load session
|
|
|
|
L.login(USER, PASSWORD) # (login)
|
|
|
|
L.interactive_login(USER) # (ask password on terminal)
|
|
|
|
L.load_session_from_file(USER) # (load session created w/
|
|
|
|
# `instaloader -l USERNAME`)
|
|
|
|
|
|
|
|
:mod:`instaloader` provides the :class:`Post` structure, which represents a
|
|
|
|
picture, video or sidecar (set of multiple pictures/videos) posted in a user's
|
|
|
|
profile. :class:`Instaloader` provides methods to iterate over Posts from a
|
|
|
|
certain source::
|
|
|
|
|
|
|
|
for post in L.get_hashtag_posts('cat'):
|
|
|
|
# post is an instance of instaloader.Post
|
|
|
|
L.download_post(post, target='#cat')
|
2017-09-08 10:35:38 +02:00
|
|
|
|
2017-11-14 11:18:30 +01:00
|
|
|
Besides :func:`Instaloader.get_hashtag_posts`, there is
|
2018-03-14 08:41:48 +01:00
|
|
|
:func:`Instaloader.get_feed_posts`, :func:`Instaloader.get_profile_posts` and
|
|
|
|
:func:`Instaloader.get_saved_posts`.
|
2017-11-14 11:18:30 +01:00
|
|
|
Also, :class:`Post` instances can be created with :func:`Post.from_shortcode`
|
|
|
|
and :func:`Post.from_mediaid`.
|
|
|
|
|
|
|
|
Further, information about profiles can be easily obtained. For example, you may
|
|
|
|
print a list of all followees and followers of a profile with::
|
2017-09-08 10:35:38 +02:00
|
|
|
|
|
|
|
# Print followees
|
|
|
|
print(PROFILE + " follows these profiles:")
|
2017-11-14 11:18:30 +01:00
|
|
|
for f in L.get_followees(PROFILE):
|
2017-09-08 10:35:38 +02:00
|
|
|
print("\t%s\t%s" % (f['username'], f['full_name']))
|
|
|
|
|
|
|
|
# Print followers
|
|
|
|
print("Followers of " + PROFILE + ":")
|
2017-11-14 11:18:30 +01:00
|
|
|
for f in L.get_followers(PROFILE):
|
2017-09-08 10:35:38 +02:00
|
|
|
print("\t%s\t%s" % (f['username'], f['full_name']))
|
|
|
|
|
2017-11-14 11:18:30 +01:00
|
|
|
Then, you may download all pictures of all followees with::
|
2017-09-08 10:35:38 +02:00
|
|
|
|
2017-11-14 11:18:30 +01:00
|
|
|
for f in L.get_followees(PROFILE):
|
|
|
|
L.download_profile(f['username'])
|
2017-09-08 10:35:38 +02:00
|
|
|
|
2017-11-14 11:18:30 +01:00
|
|
|
Each Instagram profile has its own unique ID which stays unmodified even if a
|
|
|
|
user changes his/her username. To get said ID, given the profile's name, you may
|
|
|
|
call::
|
2017-09-08 10:35:38 +02:00
|
|
|
|
2017-11-14 11:18:30 +01:00
|
|
|
L.get_id_by_username(PROFILE_NAME)
|
2017-08-25 16:54:36 +02:00
|
|
|
|
2017-11-14 11:18:30 +01:00
|
|
|
A reference of the many methods provided by the :mod:`instaloader` module is
|
|
|
|
provided in the remainder of this document. Feel free to direct any issue or
|
|
|
|
contribution to
|
2018-03-13 13:28:44 +01:00
|
|
|
`Instaloader on Github <https://github.com/instaloader/instaloader>`__.
|
2017-08-25 16:54:36 +02:00
|
|
|
|
|
|
|
``Instaloader`` (Main Class)
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
2017-09-08 10:35:38 +02:00
|
|
|
.. autoclass:: Instaloader
|
|
|
|
:no-show-inheritance:
|
2017-08-29 11:03:12 +02:00
|
|
|
|
2017-08-25 16:54:36 +02:00
|
|
|
``Post`` Class
|
|
|
|
^^^^^^^^^^^^^^
|
|
|
|
|
2017-09-08 10:35:38 +02:00
|
|
|
.. autoclass:: Post
|
|
|
|
:no-show-inheritance:
|
|
|
|
|
|
|
|
Miscellaneous Functions
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
.. autofunction:: shortcode_to_mediaid
|
|
|
|
|
|
|
|
.. autofunction:: mediaid_to_shortcode
|
|
|
|
|
|
|
|
.. autoclass:: Tristate
|
|
|
|
|
|
|
|
Exceptions
|
|
|
|
^^^^^^^^^^
|
|
|
|
|
|
|
|
.. autoexception:: InstaloaderException
|
|
|
|
:no-show-inheritance:
|
|
|
|
|
|
|
|
.. autoexception:: QueryReturnedNotFoundException
|
|
|
|
|
|
|
|
.. autoexception:: ProfileNotExistsException
|
|
|
|
|
|
|
|
.. autoexception:: ProfileHasNoPicsException
|
|
|
|
|
|
|
|
.. autoexception:: PrivateProfileNotFollowedException
|
|
|
|
|
|
|
|
.. autoexception:: LoginRequiredException
|
|
|
|
|
|
|
|
.. autoexception:: InvalidArgumentException
|
|
|
|
|
|
|
|
.. autoexception:: BadResponseException
|
|
|
|
|
|
|
|
.. autoexception:: BadCredentialsException
|
|
|
|
|
|
|
|
.. autoexception:: ConnectionException
|