How to scroll a div when ajax is used to load data in selenium python

I am working on python selenium with chrome-webdriver in window 8. I came across a page that loads data while scrolling using ajax.I tried typing jquery and the following links do not work for me.  Link 1 Link 2 Link 3

Can someone give me the right way to follow.

EDIT -------------

This is my incomplete code after alecx answer

    nam = driver.find_element(By.CLASS_NAME ,'_wu')

    #get length of review
    revcnt = driver.find_element(By.XPATH ,"//span[@class='_Mnc _yz']")
    revcnt = int(revcnt.text.replace(" reviews","").strip())
    print revcnt
    # wait for reviews to appear
    wait = WebDriverWait(driver, 10)
    wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "span.review-snippet")))
    #reviews=[]
    while True:
        reviews = driver.find_elements_by_css_selector("div._ju")
        if len(reviews)<revcnt:
            driver.execute_script("arguments[0].scrollIntoView();", reviews[-1])
        else:
            driver.quit()
        print len(reviews)

But the problem is getting out of the while! Loop

I tried it .

+4
source share
1

"" ( ):

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get("https://www.google.com/search?q=a1%20plumbing%20boise&gws_rd=ssl#gws_rd=ssl&lrd=0x54aeff4cb0b24461:0x23720b81e2bed658,1")

# wait for reviews to appear
wait = WebDriverWait(driver, 10)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "span.review-snippet")))

while True:
    reviews = driver.find_elements_by_css_selector("div._ju")
    driver.execute_script("arguments[0].scrollIntoView();", reviews[-1])

, - , . , , . , . - , .

, , - , - , :

dialog = driver.find_element_by_css_selector("div.review-dialog-list")
last_scroll_height = 0

while True:
    reviews = driver.find_elements_by_css_selector("div._ju")
    driver.execute_script("arguments[0].scrollIntoView();", reviews[-1])

    # adding artificial delay (don't tell anyone I'm using sleep here)
    time.sleep(1)

    # if scroll height has not changed - exit
    scroll_height = driver.execute_script("return arguments[0].scrollHeight;", dialog)
    if scroll_height == last_scroll_height:
        break
    else:
        last_scroll_height = scroll_height

print(len(reviews)) 

time.sleep() , , .

+3

Source: https://habr.com/ru/post/1607726/


All Articles