我在创建一个自动结帐过程的程序时遇到了一些麻烦。我正在使用 python 3 和 Selenium。该程序解析一系列日期,这些日期在页面上作为可用的四个可用插槽输出。如果当前页面上没有可用的,它将单击“下一步”按钮并搜索接下来的四个日期。如果它到达可用日期范围的末尾并且一无所获,它将等待 30 秒并重置并重新开始。
我已经完成了大部分工作,除了两个问题:
1) 我正在尝试添加一个参数,当包含该参数时,它将超越基本功能(即使用 Twilio 通过文本简单地通知用户),并完成完整的结帐过程。
这是我正在使用的python代码:
def find_available(args):
dates_available = True
spaces_free = False
free_spaces = ""
while not spaces_free:
while dates_available:
time.sleep(1.5)
spots = driver.find_elements_by_css_selector('.ss-carousel-item')
for spot_index, spot in zip(range(date_range), spots):
if spot.value_of_css_property('display') != 'none':
spot.click()
available_dates = driver.find_elements_by_css_selector('.Date-slot-container')
for available_date in available_dates:
if available_date.value_of_css_property('display') != 'none':
selected_spot = available_date.find_element_by_css_selector('#slot-container-UNATTENDED')
if 'No doorstep delivery' not in selected_spot.text:
free_spaces = selected_spot.text.replace('Select a time', '').strip()
spaces_free = True
else:
print(selected_spot.text.replace('Select a time', '').strip())
预期行为
如果程序使用'--checkout' 或'-c' 参数启动,那么一旦'spaces-free' 设置为true,它应该发送一个带有'free_spaces' 元素内的文本的文本。然后它应该进入下一个阶段,这将是选择包含文本“Soonest available”的单选按钮(如选择包含可用时隙的第一个可用单选按钮),然后单击继续按钮.
实际行为
该程序将运行,找到一个可用的时间段,然后简单地继续到接下来的几天,从不尝试选择单选按钮并在结帐过程中前进。
我究竟做错了什么?
任何帮助,将不胜感激。
函数式编程
相关分类