How can I scroll a web page using selenium webdriver in python?

前端 未结 18 1955
孤街浪徒
孤街浪徒 2020-11-22 07:04

I am currently using selenium webdriver to parse through facebook user friends page and extract all ids from the AJAX script. But I need to scroll down to get all the friend

18条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 07:34

    if you want to scroll within a particular view/frame (WebElement), what you only need to do is to replace "body" with a particular element that you intend to scroll within. i get that element via "getElementById" in the example below:

    self.driver.execute_script('window.scrollTo(0, document.getElementById("page-manager").scrollHeight);')
    

    this is the case on YouTube, for example...

提交回复
热议问题