python - 为什么我会收到“语法警告对象不可调用;可能缺少逗号”?
问题描述
我正在尝试编写一个程序来监控网站上的鞋子价格,但我收到一条错误消息:
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
文字,就好像它是一个带参数的函数一样。改成:
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)
我所做的只是添加三个逗号,并删除要打印的值周围的无意义的括号。
推荐阅读
- sql-server - 从 SQL Server 评估版迁移到 SQL Server Express
- flutter - 带有验证器的 FormField 不显示错误消息
- javascript - 添加到联系人,例如添加到日历按钮/ html/ Ajax 选项
- python - 如何获取从客户端发送的请求的时间戳?
- php - 仅使用 PHP 从值数组创建表
- ios - `retrieveConnectedPeripherals(withServices:)` 是 `retrievePeripherals(withIdentifiers:)` 的子集吗?
- angular - Angular 6 服务工作者和路由
- amazon-web-services - 在 AWS 中使用 Terraform 模块导入 Terraform
- vue.js - 将 props 传递给其他组件
- javascript - JS/ES6 - 将字符串拆分为数组,将元素保存在数组中(大小写密集)