def post_data(self, url): source = requests.get(url, headers=self.headers).text self.data = parse_json(source, JSON_CSS_SELECTOR, hook.shortcode_media) type = self._get_type(self.data) url = self._get_url(self.data, type) return (url, type)
def _check_limit(self, limit): """Return limit that is less than or equal to existing posts.""" try: total_posts = parse_json(self.driver.page_source, JSON_CSS_SELECTOR, hook.user_post_count) except KeyError: total_posts = parse_json( self.driver.page_source, JSON_CSS_SELECTOR, hook.hashtag_post_count, ) if limit > total_posts: return total_posts return limit
def _is_public(self, hashtag=False): """Return true if account is public.""" if not hashtag: private = parse_json(self.driver.page_source, JSON_CSS_SELECTOR, hook.private_profile) if private: return False return True
def test_parse_json_post_graphsidecar(self): json_data = parse_json(self.graphsidecar, self.selector, hook.shortcode_media) self.assertEqual(json_data["__typename"], "GraphSidecar")
def test_parse_json_post_graphvideo(self): json_data = parse_json(self.graphvideo, self.selector, hook.shortcode_media) self.assertEqual(json_data["__typename"], "GraphVideo")
def test_parse_json_post_graphimage(self): json_data = parse_json(self.graphimage, self.selector, hook.shortcode_media) self.assertEqual(json_data["__typename"], "GraphImage")
def test_parse_json_hashtag(self): json_data = parse_json(self.hashtag, self.selector, hook.hashtag_post_count) self.assertEqual(json_data, 105667)
def test_parse_json_username(self): json_data = parse_json(self.username, self.selector, hook.private_profile) self.assertFalse(json_data)