嗨,我正在python中试用selenium

嗨,我正在python中试用selenium,python,python-3.x,selenium,error-handling,Python,Python 3.x,Selenium,Error Handling,大家好,我正在python中试用selenium,我基本上想加载这个网站,让每个产品都有一个名称和价格。我也在使用tkinter GUI,如果其中任何一个让您感到困惑,那么例如,我运行它,它加载主菜单,单击我想查看的部分,它打开浏览器,现在加载,然后每次都会遇到此错误 Exception in Tkinter callback Traceback (most recent call last): File "E:\Python\lib\tkinter\__init__.py&quo

大家好,我正在python中试用selenium,我基本上想加载这个网站,让每个产品都有一个名称和价格。我也在使用tkinter GUI,如果其中任何一个让您感到困惑,那么例如,我运行它,它加载主菜单,单击我想查看的部分,它打开浏览器,现在加载,然后每次都会遇到此错误

Exception in Tkinter callback
Traceback (most recent call last):
  File "E:\Python\lib\tkinter\__init__.py", line 1883, in __call__
    return self.func(*args)
  File "C:\Users\James\Desktop\WebScraper\webscraper.py", line 34, in <lambda>
    scrapeBtn = tkinter.Button(secndmenu, text='scrape', command=lambda url=url:scrape(url,secndmenu))
  File "C:\Users\James\Desktop\WebScraper\webscraper.py", line 49, in scrape
    print(products.get_attribute('text'))
AttributeError: 'list' object has no attribute 'get_attribute'

仅仅阅读错误消息,不知道TkInter或Selenium的任何细节,告诉我
产品
是一个
列表
,在Python中,您不能调用列表上的
get\u属性

我假设
products
是一个具有类名
productListItem
的浏览器元素列表,因此,您想要的是获得该列表中的元素,然后对这些元素调用
get\u attribute

所以也许

对于产品中的产品:
打印(product.get_属性('text'))

可能有用。

如果您想要列表,则可以使用find\u元素作为单个项目。这会产生结果,但不是我期望的结果。它会将输出显示为所有元素都没有。尽管我已经知道如何获得所需的输出,但感谢您的帮助,因为这确实有帮助
#imports
from selenium import webdriver
import tkinter

#Window Calls
home = tkinter.Tk()
home.title("Home")
home.geometry('500x500')

urlselec=''

def shopClothing():
    urlselec="https://www.jdsports.co.uk/c/clothing/?max=72"
    url = urlselec
    return url, scrapeOrAuto(url)

def shopFootWare():
    urlselec='https://www.jdsports.co.uk/c/footwear/?max=72'
    url = urlselec
    return url, scrapeOrAuto(url)

def shopAccessories():
    urlselec='https://www.jdsports.co.uk/c/accessories/'
    url = urlselec
    return  url, scrapeOrAuto(url)


def scrapeOrAuto(url):
    home.withdraw()
    secndmenu = tkinter.Tk()
    secndmenu.title('Choose')
    secndmenu.geometry('300x300')
    url = url
    scrapeBtn = tkinter.Button(secndmenu, text='scrape', command=lambda url=url:scrape(url,secndmenu))

    scrapeBtn.pack()
    secndmenu.mainloop()

def scrape(url,secndmenu):
    secndmenu.withdraw()
    scraperAlert = tkinter.Tk()
    scraperAlert.title('Alert!')
    scraperAlert.geometry('300x200')

    tkinter.Label(scraperAlert,text='Scraping!').pack()
    browser = webdriver.Chrome()
    browser.get(url)
    products = browser.find_elements_by_class_name("productListItem ")
    print(products.get_attribute('text'))
    # soruce = browser.page_source
    print(products)

    return print('scraped')

#Buttons
clothing = tkinter.Button(anchor='center',text="Clothing", command =shopClothing)
footware = tkinter.Button(anchor='center',text='Footware', command=shopFootWare)
accessories = tkinter.Button(text='Accessories', command=shopAccessories)



#WindowCompile
clothing.pack()
footware.pack()
accessories.pack()
home.mainloop()