外部依存関係のないInstagram用のPythonパッケージ


Instagramユーザーの情報、データ、ハッシュタグ、および場所のデータをスクレイプします。このパッケージは、ユーザーの最近の投稿を、いいね、コメント、キャプションなどの情報をいくつか削除します。外部依存関係はありません。
pip install instagramy
pip install instagramy --upgrade
InstagramyセッションIDを介してInstagramにログインする必要があります。ユーザー名またはパスワードは必要ありません。セッションIDを取得するには、ブラウザを介してInstagramにログインする必要があります
注:セッション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 、 InstagramPost InstagramHashTagのクラスの選択です。
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とスラッグをパラメーターとして使用します。 Instagramの場所のURLまたはInstagramPost.location.idおよびInstagramPost.location.slugのプロパティからロケーションIDとスラグを取得できます。
> >> 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とスラッグを取得することもできます
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は必須ではありませんが、4〜5回のリクエストの後、 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によって作成されたすべてのキャッシュを現在の監督でクリアする
> >> from instagramy . core . cache import clear_caches
> >> clear_caches () # clear all caches of instagramy現在のdirでInstagramyによって作成されたすべてのキャッシュファイルのリスト
> >> 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 and InstagramLocation.location_dataは、Python dictですPropertiesセッションIDでInstagramに大きなリクエストを送信すると、Instagramが禁止される場合があります。私は、このプログラムによって引き起こされた誤用や損害について責任を負いません。
MITライセンス
貢献は大歓迎です。問題のバグを自由に報告し、プルリクエストを作成してバグを修正してください。コメント、提案、改善、強化はいつでも大歓迎です。ここでそれについてdisscussにしましょう。