MCPcopy
hub / github.com/InstaPy/InstaPy / get_links_from_feed

Function get_links_from_feed

instapy/like_util.py:46–79  ·  view source on GitHub ↗

Fetches random number of links from feed and returns a list of links

(browser, amount, num_of_search, logger)

Source from the content-addressed store, hash-verified

44
45
46def get_links_from_feed(browser, amount, num_of_search, logger):
47 """Fetches random number of links from feed and returns a list of links"""
48
49 feeds_link = "https://www.instagram.com/"
50
51 # Check URL of the webpage, if it already is in Feeds page, then do not
52 # navigate to it again
53 web_address_navigator(browser, feeds_link)
54
55 for i in range(num_of_search + 1):
56 browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
57 update_activity(browser, state=None)
58 sleep(2)
59
60 # get links
61 link_elems = browser.find_elements(
62 By.XPATH, read_xpath(get_links_from_feed.__name__, "get_links")
63 )
64
65 total_links = len(link_elems)
66 logger.info("Total of links feched for analysis: {}".format(total_links))
67 links = []
68 try:
69 if link_elems:
70 links = [link_elem.get_attribute("href") for link_elem in link_elems]
71 logger.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~")
72 for i, link in enumerate(links):
73 print(i, link)
74 logger.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~")
75
76 except BaseException as e:
77 logger.error("link_elems error \n\t{}".format(str(e).encode("utf-8")))
78
79 return links
80
81
82def get_main_element(browser, link_elems, skip_top_posts):

Callers 1

Calls 5

web_address_navigatorFunction · 0.85
update_activityFunction · 0.85
sleepFunction · 0.85
read_xpathFunction · 0.85
execute_scriptMethod · 0.80

Tested by

no test coverage detected