[英]How can i fix this stupid python syntax error
I keep getting this stupid syntax error.我不断收到这个愚蠢的语法错误。 Solving this error could be the last thing i need before i can finally upgrade my pc and get a gpu.
在我最终升级我的电脑并获得 gpu 之前,解决这个错误可能是我需要做的最后一件事。 Syntax error line 28
语法错误第 28 行
File "autobot.py", line 28 except: ^文件“autobot.py”,第 28 行,除了:^
SyntaxError: invalid syntax SyntaxError:无效的语法
I get the syntax error when i try to run the script This syntax error is very annoying当我尝试运行脚本时出现语法错误这个语法错误很烦人
Im just trying to create a bot that will add a GPU to my cart because its my last resort to actually get a card.我只是想创建一个机器人,它将 GPU 添加到我的购物车中,因为这是我实际获得卡片的最后手段。 All these scalpers are annoying so im just gonna make my own bot to buy me one gpu.
所有这些黄牛都很烦人,所以我只想让我自己的机器人给我买一个 gpu。
from selenium import webdriver
# For Using Chrome
browser = webdriver.Chrome('/Users/matthewsievenpiper/vhromedriver')
# Bestbuy Founder Edition RTX 3080 Page
browser.get('https://www.bestbuy.com/site/nvidia-geforce-rtx-3080-10gb-gddr6x-pci-express-4-0-graphics-card-titanium-and-black/6429440.p?skuId=6429440')
# Bestbuy purchaseable page
#browser.get('https://www.bestbuy.com/site/seagate-barracuda-2tb-internal-sata-hard-drive-for-desktops/6344172.p?skuId=6344172')
buyButton = False
while not buyButton:
try:
#If this works then button is not pytopen
addToCartBtn = addButton = browser.find_element_by_class_name("btn-disabled")
# Button isnt open restart the script
print("Button isn't ready yet.")
# Refresh page after delay
time.sleep(1)
browser.refresh()
line 28 except:
addToCartBtn = addButton = browser.find_element_by_class_name("btn-primary")
# Click the button and end the script
print("Button was clicked!")
addToCartBtnbuyButton.click()
buyButton = True
Mind the indentation.注意缩进。
except
should be at the same line indentation as try
. except
应该与try
处于同一行缩进。
from selenium import webdriver
# For Using Chrome
browser = webdriver.Chrome('/Users/matthewsievenpiper/vhromedriver')
# Bestbuy Founder Edition RTX 3080 Page
browser.get('https://www.bestbuy.com/site/nvidia-geforce-rtx-3080-10gb-gddr6x-pci-express-4-0-graphics-card-titanium-and-black/6429440.p?skuId=6429440')
# Bestbuy purchaseable page
#browser.get('https://www.bestbuy.com/site/seagate-barracuda-2tb-internal-sata-hard-drive-for-desktops/6344172.p?skuId=6344172')
buyButton = False
while not buyButton:
try:
#If this works then button is not pytopen
addToCartBtn = addButton = browser.find_element_by_class_name("btn-disabled")
# Button isnt open restart the script
print("Button isn't ready yet.")
# Refresh page after delay
time.sleep(1)
browser.refresh()
except: # should be at same line as 'try'
addToCartBtn = addButton = browser.find_element_by_class_name("btn-primary")
# Click the button and end the script
print("Button was clicked!")
addToCartBtnbuyButton.click()
buyButton = True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.