感想

最近发现了一个好用的python library:Instaloader,它能够做很多操作,我这里利用这个包从instagram上下载图片+hashtag数据。

安装

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​