第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在python中使用selenium webdriver滾動網(wǎng)頁?

如何在python中使用selenium webdriver滾動網(wǎng)頁?

慕哥9229398 2019-08-09 16:41:13
如何在python中使用selenium webdriver滾動網(wǎng)頁?我目前正在使用selenium webdriver來解析Facebook用戶朋友頁面并從AJAX腳本中提取所有ID。但我需要向下滾動才能吸引所有朋友。如何在Selenium中向下滾動。我正在使用python。
查看完整描述

3 回答

?
阿晨1998

TA貢獻2037條經(jīng)驗 獲得超6個贊

您可以使用

driver.execute_script("window.scrollTo(0, Y)")

其中Y是高度(在全高清監(jiān)視器上它是1080)。(感謝@lukeis)

你也可以使用

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

滾動到頁面底部。

如果你想scrool到一個無限加載的頁面,如社交網(wǎng)絡,F(xiàn)acebook等(感謝@Cong Tran)

SCROLL_PAUSE_TIME = 0.5# Get scroll heightlast_height = driver.execute_script("return document.body.scrollHeight")while True:
    # Scroll down to bottom
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

    # Wait to load page
    time.sleep(SCROLL_PAUSE_TIME)

    # Calculate new scroll height and compare with last scroll height
    new_height = driver.execute_script("return document.body.scrollHeight")
    if new_height == last_height:
        break
    last_height = new_height


查看完整回答
反對 回復 2019-08-09
?
拉風的咖菲貓

TA貢獻1995條經(jīng)驗 獲得超2個贊

from selenium.webdriver.common.keys import Keyshtml = browser.find_element_by_tag_name('html')html.send_keys(Keys.END)

測試,它的工作原理


查看完整回答
反對 回復 2019-08-09
  • 3 回答
  • 0 關注
  • 699 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號