【发布时间】:2021-07-16 05:02:19
【问题描述】:
我的第一个 python 项目需要一些帮助(也是我在 stackoverflow 上的第一篇文章)。感谢您的时间和帮助!
我正在尝试使用 selenium 和 chrome webdriver 在网站上自动进行定期预订。预订页面是一个时间表,每个单元格对应一个时间段,每个单元格/时间段内都有“预订”按钮。
但是,这些按钮的 XPATH 是动态的。
例如//*[@id="root"]/div[4]/div/div[4]/div/div[3]/div[69]/div[3]/button
不同时间段的每个单元格和按钮都具有相同的 html 类名称和类型。那么是否可以在每个单元格中搜索文本(例如 Class 1.10 7:30)并单击同一单元格中的相应按钮?
<div class="column">
<div class="cell even">
<span class="d-block d-sm-none">Sat, 17th Jul</span>
<span class="d-none d-sm-block">Saturday, 17th July</span></div>
<div class="cell event " style="color: rgb(255, 255, 255); top: 8rem; height: 6rem;">
<div>Class 1.1</div>
<div>07:30</div>
<div class="position-relative">
<button class="btn btn-warning" type="button">Book</button>
</div>
</div>
<div class="cell event " style="color: rgb(255, 255, 255); top: 16rem; height: 6rem;">
<div>Class 1.2</div>
<div>08:30</div>
<div class="position-relative">
<button class="btn btn-warning" type="button">Book</button>
</div>
</div>
【问题讨论】:
标签: python xpath selenium-chromedriver