简体   繁体   English

Python Selenium 不会改变滚动高度谷歌地图评论

[英]Python Selenium not change Scroll Height google maps reviews

I am scrolling google maps reviews till end of scroll but I can't come outside of while loop.我正在滚动谷歌地图评论直到滚动结束,但我无法离开 while 循环。 I am trying to scroll last height and new height after scrolling but it gives same.我试图在滚动后滚动最后一个高度和新高度,但它给出了相同的。

output same height输出相同高度

2194
2194
2194 
last_height = driver.execute_script("return document.documentElement.scrollHeight")
            print(last_height)
            while True:
                scroller = driver.find_element_by_class_name('review-dialog-list')
                driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight',scroller)
                sleep(3)
                new_height= driver.execute_script("return document.documentElement.scrollHeight")
                #new_height = driver.execute_script("return window.pageYOffset;")
                print(new_height)

Finally I make a solution for this problem.最后我为这个问题提出了一个解决方案。

                while True:
                driver.execute_script("document.getElementsByClassName(\'review-dialog-list\')[0].scrollTo(0, document.getElementsByClassName(\'review-dialog-list\')[0].scrollHeight)")
                sleep(5)
                new_height = driver.execute_script("return document.getElementsByClassName(\'review-dialog-list\')[0].scrollHeight")
                #print('new_height:', new_height)
                if new_height == last_height:
                    break
                else:
                    last_height = new_height

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM