我正在使用python3.6硒网络驱动程序与google-maps部分结果进行交互。但是,我希望我的搜寻器在循环显示结果时自动向下滚动此部分,从而使其行为更像人类。
我试图让div元素负责滚动结果部分,然后执行element.click()
,但是没有用。
请注意,按照建议的 here 执行webdriver.execute_script("window.scrollTo(0,Y)")
无济于事。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
# starting the web driver
browser = webdriver.Chrome()
# loading the page
browser.get('https://www.google.com/maps?hl=en')
# passing the search parameters
inputField = browser.find_element_by_id('searchboxinput')
inputField.send_keys('coffe shop spokane wa')
button = browser.find_element_by_id('searchbox-searchbutton')
# searching
button.click()
# grabbing the element responsible for the scroll bar
div = browser.find_element_by_xpath("//div[@class='section-listbox section-scrollbox scrollable-y scrollable-show section-listbox-flex-vertical section-listbox-scrolled']")
div.click()