滚动 Facebook 中的人员列表,将滚动条向下滚动到末尾。我的代码无法正常工作。我该如何解决?

Scroll the people list in Facebook, bringing the scrollbar down to the end. My code not working correctly. How can I solve?

我想向下滚动,直到滚动的最大端(直到最后一个人的名字),在 Facebook 上留下赞的人列表(在“全部”部分)。 link,例如来自纽约时报 post,是这样的:https://www.facebook.com/nytimestravel/photos/a.142272672496512/5176942835696112/(也许要查看你必须使用你的 facebook 登录,我不知道)

我正在使用此代码,但它不起作用:

#code for access to facebook with driver in firefox
#(i avoid writing so as not to stretch and be more synthetic)
# ....

#scrollbar
element = driver.find_element(By.XPATH,'/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div[2]/div/div[1]/div/div[3]')
driver.execute_script("return arguments[0].scrollIntoView();", element)

我没有收到任何错误,但问题是,使用这段代码,没有任何反应。垂直滚动条不移动,列表不向下滚动

我试过使用几个 xpatches,但它们都不起作用。我正在使用这段代码。不知道是我输入的xpatch错了还是整个代码错了。谁能帮我?谢谢

更新 有关其他信息,请使用此 class 打开浏览器并使用 Firefox 进行模拟(显然这只是代码的一部分。为了使问题简洁,我没有全部插入)

class Facebook:
    #Access Facebook
    #/usr/bin/firefox/firefox
    profile_path = '....'

    options=Options()
    options.set_preference('profile', profile_path)
    options.set_preference('network.proxy.type', 4)
    options.set_preference('network.proxy.socks', '127.0.0.1')
    options.set_preference('network.proxy.socks_port', 9050)
    options.set_preference("network.proxy.socks_remote_dns", False)
    #options.set_preference("network.cookie.cookieBehavior", 0) #http://kb.mozillazine.org/Network.cookie.cookieBehavior

    service = Service('/home/xxxx/bin/geckodriver')
    global driver
    driver = Firefox(service=service, options=options)
    driver.set_window_size(600, 990)
    driver.set_window_position(1, 1)
    driver.get("http://www.facebook.com")

    #Cookie prima del login
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button[data-cookiebanner="accept_button"]'))).click()

    #Login
    username_box = driver.find_element(By.ID, 'email')
    username_box.send_keys(email.get())
    password_box = driver.find_element(By.ID, 'pass')
    password_box.send_keys(password.get())

    #Open link
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div[2]/div[1]/div/div/div/div[2]/div/div[1]/form/div[2]/button'))).click()

    #Click on icon-blu like
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@class='j1lvzwm4']"))).click()

    #Click on All
    WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[1]/div/div[4]/div/div/div[1]/div/div[2]/div/div/div/div[1]/div/div/div/div/div[2]/div[2]'))).click()

reaction 的提示打开后 (in div),您可以使用下面的 xPath

//div[@data-visualcompletion='ignore-dynamic' and not(@role) and not(@class)]

这将针对该提示中的每一行。

代码:

driver.maximize_window()
driver.implicitly_wait(30)
wait = WebDriverWait(driver, 20)

driver.get("https://www.facebook.com/")

#try:
    #Cookie prima del login
    #WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button[data-cookiebanner="accept_button"]'))).click()
#except:
    #pass

#Login
wait.until(EC.visibility_of_element_located((By.ID, "email"))).send_keys('user id here')
wait.until(EC.visibility_of_element_located((By.ID, "pass"))).send_keys('password here')

#Click on login
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[name='login']"))).click()
time.sleep(2)
driver.get("https://www.facebook.com/nytimestravel/photos/a.142272672496512/5176942835696112/")

time.sleep(2)
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[@aria-label='See who reacted to this']"))).click() #this is to click on like, and reaction button
time.sleep(4)
# Click on All
WebDriverWait(driver, 200).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[1]/div/div[4]/div/div/div[1]/div/div[2]/div/div/div/div[1]/div/div/div/div/div[2]/div[2]'))).click()

i = 1
while True:
    try:
        row = wait.until(EC.visibility_of_element_located((By.XPATH, f"(// div[@ data-visualcompletion='ignore-dynamic' and not ( @ role) and not (@class )])[{i}]")))
        time.sleep(0.5)
        driver.execute_script("arguments[0].scrollIntoView(true);", row)
        i = i + 1
    except:
        print('Scrolled all the element, and must have not found the index hence break from the loop')
        break