我试图抓取谷歌地图评论,但当我试图实现滚动部分时,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上尝试了其他建议,但都没有成功。有什么想法吗?我该如何实现这一部分?
UPD:这是使用的谷歌地图链接:https://www.google.com/maps/place/El+TabanKo/@42.848117,-26741402,19z/数据=!4m15!1米7!3m6!1s0xd4fc26e313bc85:0xb10d327c782f87fa!2校正%C3%ADa+Kalea,+45,+001001+Gasteiz,+Araba!3b1!8m2!3d42.8480012!4d-2.6737255!3m6!1s0xd4fc26e26c5be1:0x5f5e0ee05fe08041!8m2!3d42.8481171!4d-2.6735931!9m1!1b1
正如我所看到的,该元素正确且唯一的css选择器是
div.section-layout.section-scrollbox
所以,试试这个:
scrollable_div = self.driver.find_element_by_css_selector('div.section-layout.section-scrollbox')