Skip to content

Commit

Permalink
Changed get_followers & get_following to include ability to scrape th…
Browse files Browse the repository at this point in the history
…rough the GraphQL API
  • Loading branch information
davidwickerhf committed Jan 18, 2021
1 parent 72b61b9 commit 7e5860b
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 54 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ The only thing you need to worry about is to spread your requests throughout the

## Features
- Scraping
- Scrape a user's followers
- Scrape a user's followers (Via scrolling or with GraphQL)
- Scraoe a user's following (Via scrolling or with GraphQL)
- Scrape a Hashtag
- Scrape a Location
- Scrape a Profile
Expand Down Expand Up @@ -53,7 +54,8 @@ The only thing you need to worry about is to spread your requests throughout the
- [ ] Interact with posts on feed
- [ ] View feed stories
- [ ] View user stories

- [ ] Save/Unsave posts

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install instaclient.
Expand Down
3 changes: 3 additions & 0 deletions instaclient/client/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def connect(self: 'InstaClient', login=False, retries=0, func=None):
if self.proxy:
chrome_options.add_argument('--proxy-server=%s' % self.proxy)
self.driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), chrome_options=chrome_options)
return self
elif self.host_type == self.LOCAHOST:
# Running locally
chrome_options = webdriver.ChromeOptions()
Expand All @@ -134,6 +135,7 @@ def connect(self: 'InstaClient', login=False, retries=0, func=None):
chrome_options.add_argument('--proxy-server=%s' % self.proxy)

self.driver = webdriver.Chrome(executable_path=self.driver_path, chrome_options=chrome_options)
return self
else:
raise InvaildHostError(self.host_type)
else:
Expand All @@ -149,6 +151,7 @@ def connect(self: 'InstaClient', login=False, retries=0, func=None):
if login:
try:
self.login(self.username, self.password)
return self
except:
raise InstaClientError(message='Tried logging in when initiating driver, but username and password are not defined.')

Expand Down
13 changes: 12 additions & 1 deletion instaclient/client/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,15 @@ class GraphUrls:
GRAPH_ACTIVITY = 'https://www.instagram.com/accounts/activity/?__a=1'
GRAPH_POST = 'https://www.instagram.com/p/{}/?__a=1'
GRAPH_SEARCH = 'https://www.instagram.com/web/search/topsearch/?query={}'
GRAPH_LOCATION = 'https://www.instagram.com/explore/locations/{}/{}/?__a=1'
GRAPH_LOCATION = 'https://www.instagram.com/explore/locations/{}/{}/?__a=1'

GRAPH_FIRST_FOLLOWERS = 'https://www.instagram.com/graphql/query/?query_hash={QUERY_HASH}&variables=%7B%22id%22%3A%22{ID}%22%2C%22include_reel%22%3Atrue%2C%22fetch_mutual%22%3Atrue%2C%22first%22%3A24%7D'
GRAPH_CURSOR_FOLLOWERS = 'https://www.instagram.com/graphql/query/?query_hash={QUERY_HASH}&variables=%7B%22id%22%3A%22{ID}%22%2C%22include_reel%22%3Atrue%2C%22fetch_mutual%22%3Afalse%2C%22first%22%3A12%2C%22after%22%3A%22{END_CURSOR}%3D%3D%22%7D'

GRAPH_FIRST_FOLLOWING = 'https://www.instagram.com/graphql/query/?query_hash={QUERY_HASH}8&variables=%7B%22id%22%3A%22{ID}%22%2C%22include_reel%22%3Atrue%2C%22fetch_mutual%22%3Afalse%2C%22first%22%3A24%7D'
GRAPH_CURSOR_FOLLOWING = 'https://www.instagram.com/graphql/query/?query_hash={QUERY_HASH}8&variables=%7B%22id%22%3A%22{ID}%22%2C%22include_reel%22%3Atrue%2C%22fetch_mutual%22%3Afalse%2C%22first%22%3A12%2C%22after%22%3A%22{END_CURSOR}%3D%3D%22%7D'


class QueryHashes:
FOLLOWERS_HASH = '5aefa9893005572d237da5068082d8d5'
FOLLOWING_HASH = '3dec7e2c57367ef3da3d987d89f9dbc'
Loading

0 comments on commit 7e5860b

Please sign in to comment.