我正试图编写一个程序,从一个网站上监控鞋子的价格,但我得到一个错误,上面写着:
syntaxwarning object not callable;perhaps you missed a comma?
以下是我的程序代码:
from selenium import webdriver
import time
class snkrsBot:
def __init__(self, sneaker_url):
self.sneaker_url = sneaker_url
self.driver = webdriver.Chrome('./chromedriver.exe')
def get_price(self):
self.driver.get(self.sneaker_url)
price = self.driver.find_element_by_xpath('//div[@data-test="product-price"]')
return int(price.get_attribute('innerHTML').strip('£'))
def main():
url = 'https://www.nike.com/gb/t/air-max-95-essential-shoe-7hwG30/AT9865-001'
bot = snkrsBot(url)
last_price = None
while True:
price = bot.get_price()
if last_price:
if price < last_price:
print('Price dropped:'(last_price - price))
elif price > last_price:
print('Price rose:'(price - last_price))
else:
print('Price is the same'(price))
last_price = price
time.sleep(5)
你的
print
都错了;错误告诉您试图调用str
文本,就好像它是一个带参数的函数一样。改为:我所做的只是添加三个逗号,并删除要打印的值周围的无意义括号
相关问题 更多 >
编程相关推荐