这是我的在线购物机器人的代码,但是当我运行它时,会出现此错误
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将链接粘贴到用户选择的衣服类别中,但是我不能这样做。可能是问题所在,以及如何解决该问题,该链接会粘贴到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)
答案 0 :(得分:1)
您正在使用driver
方法来启动webbrowser
,但是代码的问题在于您正在driver.get()
方法中传递了一个额外的参数。
预期语法:
driver.get(URL) # URL is the url you want to open.
如果您想根据url
格式化category
,请使用以下代码:
driver.get('https://www.supremenewyork.com/shop/all/{}'.format(category.get()))
有关更多信息,请参见 documentation 。
希望这能回答您的问题!