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可能会禁止您。我对该计划造成的任何滥用或损害概不负责。
麻省理工学院许可证
欢迎捐款。请随时报告发行中的错误,并通过创建拉动请求来修复一些错误。总是欢迎评论,建议,改进和增强。在这里让它解散。