设置正确的 xpath

问题描述

我正在尝试为使用 RSelenium 设置正确的 xpath,但我在这方面不是很有经验,因此非常感谢任何帮助。 由于我不允许发布图片,因此我尝试添加指向 html 屏幕截图的链接The html

我需要 R 来抓取日期 (28-10-2020 - 13-11-2020),但到目前为止,我在使用 html.nodes 时无法设置正确的 xpath。

我正在尝试从这样的网站抓取:https://www.boligsiden.dk/adresse/topperne-9-3-33-2620-albertslund-01650532___9__3__33

解决方法

我通常在 python 而不是 R 上执行此操作

As you can see in this image when you right-click on the element concerned. You get a drop-down menu with an x-path to the element.

除此之外,站点方向和 x 路径可能会发生变化,而完整的 x 路径在短期内可能是一个不错的选择,因此我更喜欢 driver.find_element_by_xpath('//button[contains(text(),"Login")]')\ .click()

在你的情况下,这将是 find_element_by_xpath('//*[contains(@class,'u-pb-4 u-block')]')

我希望这会有所帮助,不同语言的情况大致相同