def test_from_shortcode(google_post): result_post: Post = Post.from_shortcode( shortcode=google_post.data_points[0].shortcode) result_post.static_load() assert result_post.url == google_post.url assert result_post.data_points[0].caption == google_post.data_points[ 0].caption
def _create_post_objects(self, post_soup, post_size): # create post objects for each post on the page self.posts = [] for post in post_soup: shortcode = post["href"].replace("/p/", "")[:-1] self.posts.append(Post.from_shortcode(shortcode)) if len(self.posts) >= post_size: break
def test_from_shortcode(self, page_instance): expected_post = "CGX0G64hu4Q" result_profile: Post = Post.from_shortcode(shortcode=expected_post) assert result_profile.url == page_instance.url
def page_instance(self): google_post_url = f"https://www.instagram.com/p/CGX0G64hu4Q/" random_google_post = Post(url=google_post_url) random_google_post.load() return random_google_post
def test_from_soup(self, get_request, page_instance): post_html = get_request.text post_soup = BeautifulSoup(post_html, features='lxml') post_obj = Post(post_soup) post_obj.scrape() assert post_obj.likes == page_instance.likes
def test_from_html(self, get_request, page_instance): post_html = get_request.text post_obj = Post(post_html) post_obj.scrape() assert post_obj.likes == page_instance.likes
def page_instance(self, url): random_google_post = Post(url) random_google_post.load() return random_google_post
import parser_libraries from selenium import webdriver from selenium.webdriver import Chrome from instascrape import Profile, scrape_posts, Post, Hashtag import time headers = {"user-agent": "Chrome/87.0.4389.23", "cookie": "sessionid= "} f = open('input_data.txt', 'r') posts_codes = [] for line in f: line = line.split(':')[1] line = line.split('-') if (len(line) == 4): line = line[0].strip(' ') else: line = line[0].strip(' ') + '-' + line[1].strip(' ') posts_codes.append(line) print(posts_codes) nafnaf = Profile('nafnafcol') nafnaf.scrape(headers=headers) for i in range(len(posts_codes)): nafnaf_post = Post(posts_codes[i]) nafnaf_post.scrape() print('----------------------') print(nafnaf_post.to_dict()['caption']) time.sleep(10)
def page_instance(self, url, headers): random_google_post = Post(url) random_google_post.scrape(headers=headers) return random_google_post
def google_post() -> Post: google_post_url = f"https://www.instagram.com/p/B_VEzbplCFT/" random_google_post = Post(url=google_post_url) random_google_post.static_load() return random_google_post
def google_post() -> Post: google_post_url = f"https://www.instagram.com/p/CFkIz2UlIng/" random_google_post = Post(url=google_post_url) random_google_post.load() return random_google_post
def test_from_shortcode(google_post): result_post: Post = Post.from_shortcode(shortcode=google_post.shortcode) assert result_post.url == google_post.url