Created
September 10, 2020 03:23
-
-
Save dev4Fun/606bf0bc55299411687df96b990f2763 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fetch_posts_from_explore(self, max_id=0): | |
text = self.load_pre_from_url( | |
f"https://www.instagram.com/explore/grid/?is_prefetch=false&omit_cover_media=false&module=explore_popular&use_sectional_payload=true&cluster_id=explore_all%3A0&include_fixed_destinations=true&max_id={max_id}") | |
return parse_explore(text) | |
def load_pre_from_url(self, url): | |
self.open_and_switch_to_tab(url) | |
try: | |
self.wait_until(ec.presence_of_element_located((By.TAG_NAME, 'pre')), timeout=7) | |
return self.driver.find_element_by_tag_name('pre').text | |
finally: | |
self.close_and_open_tab() | |
def open_and_switch_to_tab(self, url): | |
handles = self.driver.window_handles | |
self.driver.execute_script(f"window.open('{url}');") | |
# index based | |
self.driver.switch_to.window(self.driver.window_handles[len(handles)]) | |
def close_and_open_tab(self, tab_index=0): | |
self.driver.close() | |
self.driver.switch_to.window(self.driver.window_handles[tab_index]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment