— title: selenium缓慢拖动滚动条 date: 2022-03-23 18:53:52 categories:
- IT技术
- 爬虫
- selenium tags:
- IT技术
- 爬虫
- selenium
摘要:Version:0.9 StartHTML:0000000155 EndHTML:0000005032 StartFragment:0000000191 EndFragment:0000004996 SourceURL:https://zhuanlan.zhihu.com/p/343516637 selenium自动化模拟的时候,有时候要模拟到拖动滚动条,所以放上代码啦~ 下面代码是直接拉到
selenium缓慢拖动滚动条
Version:0.9 StartHTML:0000000155 EndHTML:0000005032 StartFragment:0000000191 EndFragment:0000004996 SourceURL:https://zhuanlan.zhihu.com/p/343516637 selenium自动化模拟的时候,有时候要模拟到拖动滚动条,所以放上代码啦~ 下面代码是直接拉到底
for i in range(4, 9):
time.sleep(0.5)
driver.execute\_script('window.scrollTo(0, document.body.scrollHeight)') time.sleep(0.5)
下面代码是缓慢拖动
js = "return action=document.body.scrollHeight"
new\_height = driver.execute\_script(js)
for i in range(0,new\_height,150):
driver.execute\_script('window.scrollTo(0, %s)'%(i))
每次150的间距拖动。。不怎么会码字。敬请谅解