Skip to content
Advertisement

Instaloader – receive media count for inputted hashtag

I’m looking to simply input a series of hashtags and be outputted with those hashtags and their associated post count.

I believe I can use the mediacount property: “The count of all media associated with this hashtag.” As found here: https://instaloader.github.io/module/structures.html?highlight=hashtag#instaloader.Hashtag

But am insure how to write the code for it.

I have tried:

from instaloader import Hashtag

Inst = Instaloader()
h = Hashtag(Inst.InstaloaderContext,"coding")
print(h.mediacount)

This left me with this error:

Traceback (most recent call last):
  File "/xxx/Hashtag.py", line 7, in <module>
    h = Hashtag(instaloader.InstaloaderContext,"coding")
  File "/xxx/instaloader/structures.py", line 1453, in __init__
    assert "name" in node
AssertionError

Advertisement

Answer

which version of instaloader APIs are you using?

I use v4.9 and the following codes can work for me

from instaloader import Hashtag
import instaloader

Inst = instaloader.Instaloader()
h = Hashtag.from_name(Inst.context,"coding")
print(h.mediacount)
output: 4855699
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement