【发布时间】:2021-07-14 05:20:57
【问题描述】:
我正在尝试为自己创建一个结帐机器人。我的代码的唯一问题是它无法检测到何时启用或禁用添加到购物车按钮。
这是我在禁用按钮时得到的输入:
<button disabled="" class="button_E6SE9 primary_1oCqK addToCartButton_1op0t addToCartButton regular_1jnnf disabled_mu48L" type="submit"><span class="content_3Dbgg" tabindex="-1"><div class="addToCartLabel_YZaVX"><span>Add to Cart</span></div></span></button>
这是我在启用按钮时得到的输入:
<button class="button_E6SE9 primary_1oCqK addToCartButton_1op0t addToCartButton regular_1jnnf" type="submit"><span class="content_3Dbgg" tabindex="-1"><div class="addToCartLabel_YZaVX"><span>Add to Cart</span></div></span></button>
这就是我要让它检测按钮的方法,但是它仅在启用按钮时才有效。
while not buyButton:
try:
addToCartBtn = addButton = browser.find_element_by_class_name("addToCartButton")
addToCartBtn.click()
print("Item in stock")
except:
addToCartBtn = addButton = browser.find_element_by_class_name("disabled_mu48L")
browser.refresh()
print("Item out of stock")
continue
我尝试过使用 XPATH 并使用不同的类名来查看它是否可以工作,但似乎没有任何效果。任何建议或提示都会有所帮助,谢谢!
【问题讨论】: