I am trying to retrieve all the links to the posts of on instagram account, however it breaks and I am currently struggling to write the proper WebDriverWait
so I could make it work.
My few attempts have taken me as close as that:
links = WebDriverWait(posts, 10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".a")))
links = [elem.get_attribute('href') for elem in links]
But it throws NameError: name 'By' is not defined
The code that I am trying to run before any adjustments were made:
browser= webdriver.Chrome('/Users/marialavrovskaa/desktop/chromedriver')
browser.get(f"{instagram_page}")
while scheight < 9.9:
browser.execute_script("window.scrollTo(0, document.body.scrollHeight/%s);" % scheight)
scheight += .01
posts += browser.find_elements_by_xpath(f"//div[@class='{xpath_to_links}']")
Here the code breaks:
links = elem.find_element_by_css_selector('a').get_attribute('href') for elem in posts]
print(links)
I've built my understanding around that error, yet I struggle to make it work with By.CSS_SELECTOR
settings. Any help will be greatly appreciated.