Selenium - 在抓取 google 地图评论时无法找到此类元素
Selenium - Unable to locate such element while scraping google maps reveiws
我正在尝试抓取 google 地图评论,但是当我尝试实现滚动部分时,selenium 抛出错误。
这是我的代码
def __scroll(self):
scrollable_div = self.driver.find_element_by_css_selector('div.section-layout.section-scrollbox.scrollable-y.scrollable-show')
self.driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', scrollable_div)
这只是滚动部分,这里 selenium 抛出错误
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"div.section-layout.section-scrollbox.mapsConsumerUiCommonScrollable__scrollable-y.mapsConsumerUiCommonScrollable__scrollable-show"}
(Session info: headless chrome=90.0.4430.212)
我尝试了关于 github 的其他建议,但 none 奏效了。有什么想法我可以如何实现这部分?
如我所见,该元素的正确且唯一的 css 选择器是
div.section-layout.section-scrollbox
所以,试试这个:
scrollable_div = self.driver.find_element_by_css_selector('div.section-layout.section-scrollbox')
我正在尝试抓取 google 地图评论,但是当我尝试实现滚动部分时,selenium 抛出错误。
这是我的代码
def __scroll(self):
scrollable_div = self.driver.find_element_by_css_selector('div.section-layout.section-scrollbox.scrollable-y.scrollable-show')
self.driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', scrollable_div)
这只是滚动部分,这里 selenium 抛出错误
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"div.section-layout.section-scrollbox.mapsConsumerUiCommonScrollable__scrollable-y.mapsConsumerUiCommonScrollable__scrollable-show"}
(Session info: headless chrome=90.0.4430.212)
我尝试了关于 github 的其他建议,但 none 奏效了。有什么想法我可以如何实现这部分?
如我所见,该元素的正确且唯一的 css 选择器是
div.section-layout.section-scrollbox
所以,试试这个:
scrollable_div = self.driver.find_element_by_css_selector('div.section-layout.section-scrollbox')