get() 接受 2 个位置参数,但给出了 3 个

get() takes 2 positional arguments but 3 were given

这是我的在线购物机器人的代码,但是当我 运行 它给了我这个错误

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\artjo\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:\Users\artjo\Desktop\Python\tkinter3.py", line 32, in web
    driver.get('https://www.supremenewyork.com/shop/all/', category)
TypeError: get() takes 2 positional arguments but 3 were given

我想要 driver.get 将 link 粘贴到用户选择的服装类别中,但它不允许我这样做。可能是什么问题以及如何解决 link 粘贴到 Chrome 栏并继续的问题。还没完呢,先别看 def web() 留下的尾巴,下面是代码。谢谢

from tkinter import *
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException

screen = Tk()
screen.geometry("600x400")
screen.title("Bot")
screen.configure(background = "red3")

def web():
    name.get()
    email.get()
    telephone.get()
    address.get()
    zipad.get()
    city.get()
    state.get()
    number.get()
    datem.get()
    datey.get()
    cvv.get()
    category.get()
    size.get()
    keyword.get()
    color.get()

    driver = webdriver.Chrome(executable_path=r'C:\Users\artjo\Desktop\Python\chrome\chromedriver.exe')
    driver.get('https://www.supremenewyork.com/shop/all/', category)

    while True:
     try:
          driver.find_element_by_partial_link_text(keyword)
          break
     except (NoSuchElementException):
          wait=WebDriverWait(driver, 10)
          waitBis=wait.until(EC.presence_of_element_located((By.ID, 'time-zone-name')))
          driver.refresh()

    driver.find_element_by_partial_link_text(keyword).click()

name = StringVar()
email = StringVar()
telephone = StringVar()
address = StringVar()
zipad = StringVar()
city = StringVar()
state = StringVar()
number = StringVar()
datem = StringVar()
datey = StringVar()
cvv = StringVar()
category = StringVar()
size = StringVar()
keyword = StringVar()
color = StringVar()

namelabel = Label(screen, width = 10, text = "name", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
namelabel.place(x = 30, y = 62)
nameentry = Entry(screen, textvariable = name, width = 20, bg = "white")
nameentry.place(x = 130, y = 64)

emaillabel = Label(screen, width = 10, text = "e-mail", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
emaillabel.place(x = 30, y = 102)
emailentry = Entry(screen, textvariable = email, width = 20, bg = "white")
emailentry.place(x = 130, y = 104)

tellabel = Label(screen, width = 10, text = "telephone", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
tellabel.place(x = 30, y = 142)
telentry = Entry(screen, textvariable = telephone, width = 20, bg = "white")
telentry.place(x = 130, y = 144)

adrlabel = Label(screen, width = 10, text = "address", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
adrlabel.place(x = 30, y = 182)
adrentry = Entry(screen, textvariable = address, width = 20, bg = "white")
adrentry.place(x = 130, y = 184)

ziplabel = Label(screen, width = 10, text = "zip", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
ziplabel.place(x = 30, y = 222)
zipentry = Entry(screen, textvariable = zipad, width = 20, bg = "white")
zipentry.place(x = 130, y = 224)

citylabel = Label(screen, width = 10, text = "city", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
citylabel.place(x = 30, y = 262)
cityentry = Entry(screen, textvariable = city, width = 20, bg = "white")
cityentry.place(x = 130, y = 264)

statelabel = Label(screen, width = 10, text = "state", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
statelabel.place(x = 30, y = 302)
stateentry = Entry(screen, textvariable = state, width = 20, bg = "white")
stateentry.place(x = 130, y = 304)

numberlabel = Label(screen, width = 10, text = "number", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
numberlabel.place(x = 320, y = 62)
numberentry = Entry(screen, textvariable = number, width = 20, bg = "white")
numberentry.place(x = 420, y = 64)

explabel = Label(screen, width = 10, text = "exp. date", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
explabel.place(x = 320, y = 102)
expentry1 = Entry(screen, textvariable = datem, width = 5, bg = "white")
expentry1.place(x = 420, y = 104)
expentry2 = Entry(screen, textvariable = datey, width = 8, bg = "white")
expentry2.place(x = 470, y = 104)

cvvlabel = Label(screen, width = 10, text = "cvv", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
cvvlabel.place(x = 320, y = 142)
cvventry = Entry(screen, textvariable = cvv, width = 5, bg = "white")
cvventry.place(x = 420, y = 144)

keywordlabel = Label(screen, width = 10, text = "keyword", bg = "orange", fg = "black", font = ("Courier", 10), anchor = W)
keywordlabel.place(x = 320, y = 222)
keywordentry = Entry(screen, textvariable = keyword, width = 20, bg = "orange")
keywordentry.place(x = 420, y = 224)

colorlabel = Label(screen, width = 10, text = "color", bg = "orange", fg = "black", font = ("Courier", 10), anchor = W)
colorlabel.place(x = 320, y = 262)
colorentry = Entry(screen, textvariable = color, width = 20, bg = "orange")
colorentry.place(x = 420, y = 264)

sizelabel = Label(screen, width = 10, text = "size", bg = "orange", fg = "black", font = ("Courier", 10), anchor = W)
sizelabel.place(x = 320, y = 300)
sizelist = ["S", "M", "L","XL"]
size.set(sizelist[0])
sizemenu = OptionMenu(screen, size, *sizelist)
sizemenu.configure(font = ("Courier", 10),bg = "orange")
sizemenu.place(x = 415, y = 302)

categorylabel = Label(screen, width = 10, text = "category", bg = "orange", fg = "black", font = ("Courier", 10), anchor = W)
categorylabel.place(x = 320, y = 182)
categorylist = ["jackets", "shirts", "tops/sweaters","sweatshirts", "pants", "shorts", "t-shirts", "hats", "bags", "accessories", "skate", "shoes"]
category.set(categorylist[0])
categorymenu = OptionMenu(screen, category, *categorylist)
categorymenu.configure(font = ("Courier", 9),bg = "orange")
categorymenu.place(x = 415, y = 184)

button1 = Button(screen, text="START", command=web)
button1.configure(font = ("Courier", 12), bg = "green", width = 10, height = 2)
button1.place(x=480,y=330)

您正在使用 driver 方法启动 webbrowser,但您的代码存在问题,您在 driver.get() 方法中传递了一个额外的参数。

预期语法:

driver.get(URL) # URL is the url you want to open.

如果你想根据 category 格式化你的 url 使用下面的代码:

driver.get('https://www.supremenewyork.com/shop/all/{}'.format(category.get()))

有关详细信息,请参阅 documentation

希望这能回答您的问题!!