您只需几行代码即可使用instascrape 来完成此操作(免责声明:我是这个包的作者)
使用pip install insta-scrape pip 安装它,然后获取用户的帐户信息,尝试
from instascrape import Profile
google = Profile("google")
google.scrape()
这会从帐户中加载几十个数据点,您可以使用点符号访问这些数据点,如 google.followers、google.following、google.is_verified 等,或者您可以使用 dict 获取所有数据987654328@
{'csrf_token': '19DnM5UYbxusoSnbfUNGGiOr5hU91khz',
'viewer': None,
'viewer_id': None,
'country_code': 'US',
'language_code': 'en',
'locale': 'en_US',
'device_id': 'A0CFC9ED-5769-4951-94B3-F26D5724FDBD',
'browser_push_pub_key': 'BIBn3E_rWTci8Xn6P9Xj3btShT85Wdtne0LtwNUyRQ5XjFNkuTq9j4MPAVLvAFhXrUU1A9UxyxBA7YIOjqDIDHI',
'key_id': '132',
'public_key': 'a185b716b7bab1acb25e88034374819c0482257a4e240736215af2253f255d61',
'version': '10',
'is_dev': False,
'rollout_hash': '7b740aa85a82',
'bundle_variant': 'metro',
'frontend_dev': 'prod',
'logging_page_id': 'profilePage_1067259270',
'show_suggested_profiles': False,
'show_follow_dialog': False,
'biography': 'Google unfiltered—sometimes with filters.',
'blocked_by_viewer': False,
'business_email': '',
'restricted_by_viewer': None,
'country_block': False,
'external_url': 'https://linkin.bio/google',
'external_url_linkshimmed': 'https://l.instagram.com/?u=https%3A%2F%2Flinkin.bio%2Fgoogle&e=ATOMCBcW4YjsNBxlDyAETnOiWt8zHrGTW0VJIufW-ROhSYM5lm2p-JNT060OLDBmMFuoszepQpW0cfEf&s=1',
'followers': 12262801,
'followed_by_viewer': False,
'following': 30,
'follows_viewer': False,
'full_name': 'Google',
'has_ar_effects': False,
'has_clips': True,
'has_guides': False,
'has_channel': False,
'has_blocked_viewer': False,
'highlight_reel_count': 6,
'has_requested_viewer': False,
'id': '1067259270',
'is_business_account': True,
'is_joined_recently': False,
'business_category_name': 'Business & Utility Services',
'overall_category_name': None,
'category_enum': 'INTERNET_COMPANY',
'is_private': False,
'is_verified': True,
'mutual_followers': 0,
'profile_pic_url': 'https://scontent-lga3-1.cdninstagram.com/v/t51.2885-19/s150x150/119515245_239175997499686_2853342285794408974_n.jpg?_nc_ht=scontent-lga3-1.cdninstagram.com&_nc_ohc=_vp0OGMhUrEAX9mEskb&oh=242d04421b13f2545952203069b164b6&oe=5FC05FDB',
'profile_pic_url_hd': 'https://scontent-lga3-1.cdninstagram.com/v/t51.2885-19/s320x320/119515245_239175997499686_2853342285794408974_n.jpg?_nc_ht=scontent-lga3-1.cdninstagram.com&_nc_ohc=_vp0OGMhUrEAX9mEskb&oh=604348546412db230d638292b39f7abe&oe=5FC2E223',
'requested_by_viewer': False,
'username': 'google',
'connected_fb_page': None,
'posts': 1416}
如果您确实只需要几个数据点,您可以将它们的名称作为键显式传递给Post.load
from instascrape import Profile
google = Profile("google")
google.scrape(keys=['followers', 'following'])
而google.to_dict() 将因此给我们
{'followers': 12262807, 'following': 30}