Python 单击 Redfin 收藏夹和 X-Out 按钮

问题描述 投票:0回答:1

对于个人用途,我想使用我的 Python Selenium 代码单击 Redfin 的“收藏夹”或“X-Out”按钮,但我无法以编程方式找到这两个按钮,并且我已经尝试了 2 天。我可以使用 Chrome 检查器看到按钮,但无法使用代码找到它们,而且我已经尝试了所有方法,我确实尝试过。我只是被困住了,需要帮助。

请告诉我如何找到每个按钮,识别它们的选择状态(已选择/未选择)以及如何单击它们以使它们来回切换选择。

我对 Python 或 Selenium 并不陌生,但我真的对这个感到困惑。我正在使用远程调试方法访问 Chrome,一旦你弄清楚了,这真的很好。它让我可以使用我的 Google 帐户登录,否则不可能使用 Selenium 那样登录。

感谢您的帮助。

这是测试链接https://www.redfin.com/TX/Roanoke/61-Cortes-Dr-76262/home/169577463 以及网站的 html 片段:

<div class="actions force-sideBarRightRail">
<div class="bp-HomeControls">
<div class="bp-pill-container-variant">
<div class="FavoriteButtonCopFlyoutWrapper HomeControlButtonWrapper">
<div class="bp-favoriteButtonWrapper bp-HomeActionsButton" data-rf-test-id="abp-favoriteButton">
<button type="button" class="bp-Button bp-homeActionButton bp-Button__type--ghost bp-Button__size--compact" tabindex="0" aria-label="Favorite this home">
<span class="ButtonIcon">
<svg class="bp-SvgIcon favorite bp-SvgIcon__size--medium">
<svg viewBox="0 0 24 24">
<path fill-rule="evenodd" clip-rule="evenodd" d="a bunch of number here"/>
</svg>
</svg>
</span>
<span class="ButtonLabel">
Favorite</span>
</button>
</div>
</div>
<div class="HomeControlButtonWrapper">
<div class="bp-xOutButtonWrapper bp-HomeActionsButton">
<button type="button" class="bp-Button bp-homeActionButton bp-Button__type--ghost bp-Button__size--compact" tabindex="0">
<span class="ButtonIcon">
<svg class="bp-SvgIcon xout bp-SvgIcon__size--medium">
<svg viewBox="0 0 24 24">
<path fill-rule="evenodd" clip-rule="evenodd" d="a bunch of numbers here"/>
</svg>
</svg>
</span>
<span class="ButtonLabel">
X-Out</span>
</button>
</div>
</div>
<div class="ShareButtonCopFlyoutWrapper HomeControlButtonWrapper">
<div class="bp-shareButtonWrapper bp-HomeActionsButton" data-rf-test-name="abp-shareButton">
<button type="button" class="bp-Button bp-homeActionButton bp-Button__type--ghost bp-Button__size--compact" tabindex="0">
<span class="ButtonIcon">
<svg class="bp-SvgIcon share bp-SvgIcon__size--medium">
<svg viewBox="0 0 25 24">
<path fill-rule="evenodd" clip-rule="evenodd" d="a bunch of numbers here"/>
</svg>
</svg>
</span>
<span class="ButtonLabel">
Share</span>
</button>
</div>
</div>
</div>
</div>
</div>
python button selenium-chromedriver screen-scraping
1个回答
0
投票

这是一种经过测试的单击

Favourite
按钮的方法:

## [..] your imports
from selenium.webdriver.support.ui import WebDriverWait
## [..] define your driver, then

wait = WebDriverWait(driver, 5)
url = 'https://www.redfin.com/TX/Roanoke/61-Cortes-Dr-76262/home/169577463'
driver.get(url)

wait.until(EC.element_to_be_clickable((By.XPATH, '//button[@aria-label="Favorite this home"]'))).click()
print('clicked favourite')

它将在终端中打印相应的消息,点击后,将显示一个新的叠加层,标题为

Favorite this home

最后,请参阅此处Selenium 文档

© www.soinside.com 2019 - 2024. All rights reserved.