angel54771 / CC

0 stars 0 forks source link

IG #1

Open angel54771 opened 3 years ago

angel54771 commented 3 years ago
# Import the module
mountain_lst=[]
import instaloader

# Create an instance of Instaloader class
good = instaloader.Instaloader(download_pictures=False,download_video_thumbnails=False,download_videos=False,download_geotags=False,download_comments=False,save_metadata=True,compress_json=False,post_metadata_txt_pattern="")
good.login("cctestfall", "asdfg0808")
#只抓json檔下來,json檔裡面的"display_url"就是每張照片的網址

def tops_posts_from_hashtag(hashtag_name: str, max_count: int):
    # Load the hashtag object into a variable
    hashtag = instaloader.Hashtag.from_name(good.context, hashtag_name)
    # Get top posts in a generator
    posts = hashtag.get_top_posts()
    for index in range(1, max_count + 1):
        try:
            # Download the post
            good.download_post(next(posts),target=f'{hashtag_name}_{index}')
        except:
            print("哭哭這座山貼文數居然不到五則")
            break # If there are any errors, we break out of the loop

for i in range(len(mountain_lst)):
    print(tops_posts_from_hashtag(mountain_lst[i],5))

print("沒有照片囉!")
angel54771 commented 3 years ago

寫了一個刪掉山的副程式可以用

mountain_lst=["大武山","波路山"] def delete__by_values(lst, values): values_as_set = set(values) return [ x for x in lst if x not in values_as_set ]

mountain_lst = delete__by_values( mountain_lst, ["波路山","良羽鳥山","馬望曾呂山","佳仁山","老松山","班山","能甲山","牧山","馬望來山","劍山","金面山"] ) print(mountain_lst)