繁体   English   中英

可用性项目检查

[英]Availability item check

import time
import os
import subprocess
from selenium import webdriver

def aval():
    driver = webdriver.Chrome()
    driver.get("webpage")
    try:
        while True:
            driver.find_element_by_xpath('xpath')
            time.sleep(5)
            print("out of stock")
            driver.refresh()
    except:
        print("in stock")
        return True


def speech():
    applescript = """
    display dialog "something in stock" ¬
    with title "This is a pop-up window" ¬
    with icon caution ¬
    buttons {"OK"}
    """

    subprocess.call("osascript -e '{}'".format(applescript), shell=True)

def comp():
    if aval() == True:
        n = 0
        while n != 7:
            os.system("say 'something is in stock'")
            n +=1
        som()

我在识别商品是否有库存时遇到问题。 我使用 XPath 来确定该项目是否有库存。 问题是,当我尝试输入可用项目时,它应该刷新页面,但相反,它说它有货。 它按我的想法工作,但我不确定为什么它应该重新加载页面时说有库存。 另外,你能批评一下我的代码吗? 我想知道你对此有何看法。

在页面上查找元素时可能会出错,这意味着它执行了 except 块。 您应该检查您的 x 路径是否正确

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM