Each pull-down document.body.scrollHeight browser interface parameters are changed, when the bottommost Selenium pulled parameter will not be changed, in order to determine whether it is the very bottom, as follows:
def pulldown():
t = True
i = 1
while t:
check_height = browser.execute_script("return document.body.scrollHeight;")
for r in range(20):
t = random.uniform(1, 2)
time.sleep(t)
browser.execute_script("window.scrollBy(0,1000)")
print('第%s页' % str(i))
i += 1
check_height1 = browser.execute_script("return document.body.scrollHeight;")
print(str(check_height)+'**************'+str(check_height1))
if check_height == check_height1:
t = False
pulldown()
selenium python3 code is as follows:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import random
path = r'E:\chromedriver.exe'
chrome_options = Options() #创建配置对象
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument("user-agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36'")
browser = webdriver.Chrome(executable_path=path,chrome_options=chrome_options)