I just let you know before I describe my problem, that I searched for same problems and I found 2 solutions that not work in this case . the questions that I looked on : raise TimeoutException(message, screen, stacktrace) TimeoutException: Message:
TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
so my mission is to scrape Instagram user profile info ( posts , followers , following ) . I tried the script serval times and everything works perfectly until i get private user . i thought maybe the XPATH has changed so i added to the followers element OR statement with another path to the element . just you to understand guys it doesnt matter if you are public user or private user in Instagram , the data that im collecting is visible for everyone because im not accessing the photos.
now as you understand I get the error message :
followers = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//header/section[1]/ul[1]/li[2]/a[1]/div[1]"))).text or WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//header/section[1]/ul[1]/li[2]/div[1]/span[1]"))).text
raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
this is my code :
insta_data = []
for name in names:
try:
# catching search input
search_input = WebDriverWait(browser, 10).until(
EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Search']")))
search_input.clear()
time.sleep(5)
search_input.send_keys(name)
count = 0
while count < 3:
search_input.send_keys(Keys.ENTER)
count += 1
time.sleep(5)
#get username
profile_username = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//h2[contains(text(),'')]"))).text
#get posts number
posts = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//header/section[1]/ul[1]/li[1]/div[1]"))).text
# try:
#get followers number
followers = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//header/section[1]/ul[1]/li[2]/a[1]/div[1]"))).text or WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//header/section[1]/ul[1]/li[2]/div[1]"))).text
# except TimeoutException:
# print("Cannot find followers.")
# browser.quit()
#get following number
following = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//header/section[1]/ul[1]/li[3]/a[1]/div[1]"))).text or WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//header/section[1]/ul[1]/li[3]/div[1]"))).text
print(profile_username, posts, followers, following)
insta_data.append((profile_username, posts, followers, following))