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来识别商品是否有现货。问题是,当我尝试输入一个可用的商品时,它应该刷新页面,但它却显示它有库存。它的工作方式和我想的一样,但我不确定为什么它是现货,而它只是应该重新加载页面。另外,你能批评一下我的代码吗?我想知道你是怎么想的。
发布于 2020-11-24 07:02:03
在页面上查找元素时可能会出现错误,这意味着它会执行except块。您应该检查您的x路径是否正确
https://stackoverflow.com/questions/64977749
复制相似问题