0

在 Quora 上,我想滚动到单击查看赞成票按钮时得到的窗口底部,以获取所有赞成票的姓名,向下滚动标准浏览器窗口的代码似乎不适用于覆盖窗口,有什么建议吗?这是我的向下滚动功能代码和单击“查看支持者”按钮的代码:

def scrolldown(browser):

    src_updated = browser.page_source
    src = ""
    while  src != src_updated:
        src = src_updated
        time.sleep(5)
        browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        time.sleep(5)
        src_updated = browser.page_source      
    #if (DEBUG): print ("window maximized...")
    return browser

browser.get('https://www.quora.com/What-is-it-like-to-regret-having-children')
for p in browser.find_elements_by_class_name('AnswerVoterListModalLink'):
        time.sleep(5)

        p.click()
        time.sleep(5)
        browser=scrolldown(browser)
        time.sleep(5)
        c=0
        for div in upvoter_name :#browser.find_elements_by_class_name('author_info'):
           list_of_upvoters.append(div.find_element_by_class_name('user').text)
           c+=1
        print("number of upvoters for this answer is :" + str(c))
4

1 回答 1

0

我认为您可以使用类似于此答案的内容向下滚动到最后一个元素。根据答案,您可以使用以下内容向下滚动到最后一个元素:

from selenium.webdriver.common.action_chains import ActionChains

element = driver.find_element_by_xpath("//div[@class='pagedlist_item'][last()]")

actions = ActionChains(driver)
actions.move_to_element(element).perform()
于 2018-09-03T05:43:52.383 回答