How to scroll a page with phantomJs

安稳与你 提交于 2019-12-05 01:05:50

问题


I wanna render a page that load its images only when the user scrolls the page. Just setting page.scrollPosition has no effect. I need something that change the scroll position over time.


回答1:


Not sure if this is the best way but it works. It evaluate a script in the page, that increase document.body.scrollTop over time and make a screenshot after a fixed time.

page.open "http://www.somePage.com", (status) ->
      setTimeout(( ->
        page.evaluate(->
          pos = 0
          scroll = ->
            pos += 250
            window.document.body.scrollTop = pos
            setTimeout(scroll, 100)

          scroll()
        )

        setTimeout((->
          page.render('bild.png')
          phantom.exit()
        ), 5000)
      ), 1000)


来源:https://stackoverflow.com/questions/16440921/how-to-scroll-a-page-with-phantomjs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!