Я хочу пролистать некоторые отзывы о ресторане на картах Google, используя веб-драйвер Selen Chrome, скажем, Nobu Palo Alto здесь:
https://www.google.com/maps/place/Nobu+Palo+Alto/@37.4437223,-122.1637038,17z/data=!3m1!4b1!4m11!1m3!2m2!1srestaurants!6e5!3m6!1s0x0:0x5bb11772add3928!8m2!3d37.4437179!4d-122.1615154!9m1!1b1
Я использовал эту функцию, которая, кажется, получает (и печатает) высоту javascript, но вместо бесконечной прокрутки она просто прерывается после печати последней высоты == новой высоты, но я знаю, что есть еще обзоры, которые не загружаются:
def __init__(self, site):
self.site=site
self.option = webdriver.ChromeOptions()
self.option.add_argument("-incognito")
self.browser = webdriver.Chrome(executable_path="C:/Users/me/Documents/project/chromedriver.exe",chrome_options=self.option)
def scroll(self):
self.browser.get(self.site)
SCROLL_PAUSE_TIME = 4
sleep(SCROLL_PAUSE_TIME)
# Get scroll height
last_height = self.browser.execute_script("return document.querySelector('#pane > div > div.widget-pane-content.scrollable-y > div > div > div.section-listbox.section-scrollbox.scrollable-y.scrollable-show').scrollHeight")
print("last height = " + str(last_height))
while True:
# Scroll down to bottom
self.browser.execute_script("window.scrollTo(0, document.querySelector('#pane > div > div.widget-pane-content.scrollable-y > div > div > div.section-listbox.section-scrollbox.scrollable-y.scrollable-show').scrollHeight);")
# Wait to load page
sleep(SCROLL_PAUSE_TIME)
# Calculate new scroll height and compare with last scroll height
new_height = self.browser.execute_script("return document.querySelector('#pane > div > div.widget-pane-content.scrollable-y > div > div > div.section-listbox.section-scrollbox.scrollable-y.scrollable-show').scrollHeight")
print("new height = " + str(new_height))
if new_height == last_height:
break
last_height = new_height