selenium 下拉到頁面最底端


selenium操控瀏覽器下拉到頁面最底端:

https://www.cnblogs.com/TTyb/p/7662430.html

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from selenium import webdriver
import time

if __name__ == '__main__':
    url = "http://blog.csdn.net/"

    browser = webdriver.Chrome()
    browser.get(url)

    browser.execute_script("""
    (function () {
    var y = 0;
    var step = 100;
    window.scroll(0, 0);
    function f() {
    if (y < document.body.scrollHeight) {
    y += step;
    window.scroll(0, y);
    setTimeout(f, 100);
    } else {
    window.scroll(0, 0);
    document.title += "scroll-done";
    }
    }
    setTimeout(f, 1000);
    })();
    """)
    print("下拉中...")
    # time.sleep(180)
    while True:
        if "scroll-done" in browser.title:
            break
    else:
        print("還沒有拉到最底端...")
        time.sleep(3)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM