python3 利用Instaloader下载instagram数据示例

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/w5688414/article/details/85061680

感想

最近发现了一个好用的python library:Instaloader,它能够做很多操作,我这里利用这个包从instagram上下载图片+hashtag数据,在此之前,你需要有一台国外的vps,在国内下载不了,本人也是咬牙租了一台,心疼money,不过也是可以承受的,少一次去外面下馆子就行了,不怎么贵。

安装

pip3 install instaloader

下载代码

download.py

with open('hashtags.txt', encoding="utf-8") as f:
    examples=f.readlines()

hashtags=[]
for item in examples:
    hashtag=item.strip().replace('#','')
    hashtags.append(hashtag)

from datetime import datetime
import instaloader
L = instaloader.Instaloader()


for HASHTAG in hashtags:
    try:
        posts = L.get_hashtag_posts(HASHTAG)
        count=0
        print(HASHTAG)
        for post in posts:
            if(post.is_video):
                continue
            if(count==10):
                break
        #         print(post.date)
            L.download_post(post, target='#'+HASHTAG)
            count+=1
    except Exception as e:
        print(e)

是不是很简单,几行代码就行了,简直吊炸天。

hastags.txt里面的为word,示例:

#love
#instagood
#photooftheday
#fashion
#beautiful
#happy
#cute
#tbt
#like4like
#followme
#picoftheday
#follow
#me
#selfie
#summer

当然还有很多其他的功能啦,详情请参考下面的文献

参考文献

[1].Instaloader.https://instaloader.github.io/index.html

猜你喜欢

转载自blog.csdn.net/w5688414/article/details/85061680
今日推荐