mercredi 6 mai 2020

Trying to scroll to end of list

i got a problem here, i'm trying to scroll to end of the list of instagram followers. It works fine when number of list is followers is small but when number is big(>600) it would not stop and keep scrolling.

    #checking if page is loaded and element is visible
    element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/section/main/div[2]/ul/div/li[1]/div/div[1]/div[2]/div[1]/a")))

    while True:

        timeElement = 0.2
        try:
        #Trying to scroll


            num =driver.find_element_by_xpath('/html').send_keys(Keys.PAGE_DOWN)
            print('Geting data...')
            time.sleep(1)
            num =driver.find_element_by_xpath('/html').send_keys(Keys.PAGE_DOWN)
            num =driver.find_element_by_xpath('/html').send_keys(Keys.PAGE_DOWN)

            #checking if it's end based on number of followers that was pass over
            try:

                print('CSS_SELECTOR')
                print (str(NumFollowers))
                element = WebDriverWait(driver, timeElement).until(
                EC.presence_of_element_located((By.CSS_SELECTOR, 'li.wo9IH:nth-child('+NumFollowers+') > div:nth-child(1) > div:nth-child(2) > button:nth-child(1)'))
                )
                print('found it')
                break
            except:
#check if xpath would work
                print('xpath')
                element = WebDriverWait(driver, timeElement).until(
                EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/section/main/div[2]/ul/div/li['+NumFollowers+']/div/div[2]/button'))
                )
                break
       #XPATH   # /html/body/div[4]/div/div[2]/ul/div/li[651]/div/div[1]/div[2]/div[1]/a
      #CSS_SELECTOR   # li.wo9IH:nth-child(651) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > a:nth-child(1)



Aucun commentaire:

Enregistrer un commentaire