Instagram的Python軟件包,沒有任何外部依賴關係


Scrape Instagram用戶信息,帖子數據,標籤和位置數據。該軟件包將用戶的最新帖子刮掉了一些信息,例如喜歡,評論,字幕等。沒有外部依賴關係。
pip install instagramy
pip install instagramy --upgrade
要通過Instagramy Session ID登錄Instagram。不需要用戶名或密碼。您必須通過瀏覽器登錄Instagram才能獲取會話ID
注意:經常檢查會話ID,可以通過Instagram更改它
類InstagramUser刮擦與Instagram用戶有關的一些信息
> >> from instagramy import InstagramUser
> >> session_id = "38566737751%3Ah7JpgePGAoLxJe%334"
> >> user = InstagramUser ( 'google' , sessionid = session_id )
> >> user . is_verified
True
> >> user . biography
'Google unfiltered—sometimes with filters.'
> >> user . user_data # More data about user as dict如果您曾經獲取用戶的數據,請Instagramy將數據存儲為緩存文件,以避免錯誤。您也可以從緩存中獲取數據。不要提供sessionID。
> >> from instagramy import InstagramUser
> >> user = InstagramUser ( 'google' , from_cache = True )
> >> user . is_verified
True它選擇了所有類InstagramUser , InstagramHashTag和InstagramPost所有類。
InstagramUser.user_data除了定義為Properties以外的數據更多
InstagramHashTag類刮擦與Instagram的標籤有關的一些信息
您還可以將SessionID設置為Env變量
$ export SESSION_ID= " 38566737751%3Ah7JpgePGAoLxJe%er40q " > >> import os
> >> from instagramy import InstagramHashTag
> >> session_id = os . environ . get ( "SESSION_ID" )
> >> tag = InstagramHashtag ( 'google' , sessionid = session_id )
> >> tag . number_of_posts
9556876
> >> tag . tag_data # More data about hashtag as dict InstagramHashTag.tag_data具有定義為Properties以外的其他數據
類InstagramPost刪除與Instagram特定帖子有關的一些信息。它將發布ID作為參數。您可以從InstagramUser.posts屬性的Instagram帖子的URL獲取帖子ID。或InstagramHagTag.top_posts
> >> from instagramy import InstagramPost
> >> session_id = "38566737751%3Ah7JpgePGAoLxJe%334"
> >> post = InstagramPost ( 'CLGkNCoJkcM' , sessionid = session_id )
> >> post . author
'ipadpograffiti'
> >> post . number_of_likes
1439
> >> post . post_data # More data about post as dict InstagramPost.post_data具有更多的數據,而不是定義為Properties
類InstagramLocation刮擦與給定位置有關的一些信息和帖子。它將位置ID和SLUG作為參數。您可以從Instagram位置的URL或InstagramPost.location.id和InstagramPost.location.slug的屬性中獲取位置ID和sl。
> >> from instagramy import InstagramPost
> >> session_id = "38566737751%3Ah7JpgePGAoLxJe%334"
> >> post = InstagramPost ( 'CLGkNCoJkcM' , sessionid = session_id )
> >> location_id , slug = post . location . id , post . location . slug
> >> from Instagramy import InstagramLocation
> >> location = InstagramLocation ( location_id , slug , session_id )
> >> location . latitude
28.6139
> >> location . longitude
77.2089
> >> location . address
{ 'street_address' : 'T2, Indira Gandhi International Airport' , 'zip_code' : '' , 'city_name' : 'New Delhi' , 'region_name' : '' , 'country_code' : 'IN' , 'exact_city_match' : False , 'exact_region_match' : False , 'exact_country_match' : False }您還可以從Instagram URL獲取位置ID和slug
https://www.instagram.com/explore/locations/977862530/mrc-nagar
https://www.instagram.com/explore/locations/<location_id>/<slug>InstagramLocation.location_data除了定義為Properties以外的數據更多
Instagramy有一些插件可輕鬆
> >> import pandas as pd
> >> from instagramy . plugins . analysis import analyze_users_popularity
> >> session_id = "38566737751%3Ah7JpgePGAoLxJe%334"
> >> teams = [ "chennaiipl" , "mumbaiindians" ,
"royalchallengersbangalore" , "kkriders" ,
"delhicapitals" , "sunrisershyd" ,
"kxipofficial" ]
> >> data = analyze_users_popularity ( teams , session_id )
> >> pd . DataFrame ( data )
Usernames Followers Following Posts
0 chennaiipl 6189292 194 5646
1 mumbaiindians 6244961 124 12117
2 royalchallengersbangalore 5430018 59 8252
3 kkriders 2204739 68 7991
4 delhicapitals 2097515 75 9522
5 sunrisershyd 2053824 70 6227
6 kxipofficial 1884241 67 7496 > >> import os
> >> from instagramy . plugins . download import *
> >> session_id = os . environ . get ( 'SESSION_ID' )
> >> download_profile_pic ( username = 'google' , sessionid = session_id , filepath = 'google.png' )
> >> download_post ( id = "ipadpograffiti" , sessionid = session_id , filepath = 'post.mp4' )
> >> download_hashtags_posts ( tag = "tamil" , session_id = session_id , count = 2 )您可以無需登錄即可使用此軟件包。不需要sessionID,但在四到五個請求後可能會增加RedirectionError錯誤。
> >> from instagramy import *
> >> user = InstagramUser ( 'google' )
> >> user . fullname
'Google'
> >> tag = InstagramHashTag ( 'python' )
> >> tag . tag_data從版本4.3中,添加了緩存所需數據的新功能。如果您曾經獲取用戶的數據,請Instagramy將數據存儲為緩存JSON文件,以避免錯誤。您也可以從緩存中獲取數據。不需要提供sessionID。而不是SessionID添加from_cache=True可選參數。
> >> from instagramy import InstagramUser
> >> user = InstagramUser ( 'google' , from_cache = True )
> >> user . is_verified
True它選擇了所有類InstagramUser , InstagramHashTag , InstagramPost和InstagramLocation所有類。
清除Instagramy在當前DIR中創建的所有caches
> >> from instagramy . core . cache import clear_caches
> >> clear_caches () # clear all caches of instagramyInstagramy在當前DIR中創建的所有緩存文件的列表
> >> from instagramy import list_caches
> >> list_caches () # list all caches of instagramy user = InstagramUser ( 'username' )
email , phone_number = user . user_data [ 'business_email' ], user . user_data [ 'business_phone_number' ]RedirectionError 。Viewer提供有關當前登錄用戶的數據。InstagramUser.user_data , InstagramPost.post_data , InstagramHashtag.tag_data和InstagramLocation.location_data是Python dict越來越多的數據,而不是定義為Properties 。如果您將巨大的請求發送到Instagram,則Instagram可能會禁止您。我對該計劃造成的任何濫用或損害概不負責。
麻省理工學院許可證
歡迎捐款。請隨時報告發行中的錯誤,並通過創建拉動請求來修復一些錯誤。總是歡迎評論,建議,改進和增強。在這裡讓它解散。