👤

Buna, stie cineva sa ma ajute la codul asta in Python?
import pandas as pd
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import tkinter
from selenium.webdriver.common.by import By

driver_a = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver_a.get("https://sofasofa.co.uk/collections/albany-collection")

product_a = []
price_a = []

def get_description():
try:
driver_a.implicitly_wait(10)
products_element = driver_a.find_elements(By.CSS_SELECTOR, "card-grid col xs12 xl10")

for product in products_element:
title = product.find_element(By.CSS_SELECTOR, "card__title subtitle-1 text-center").text
product_a.append(title)

price_text = product.find_element(By.CSS_SELECTOR, "product-price").text
price = price_text.replace("£", "").replace("From ", "").replace(",", "")
if '–' in price:
price = price.split('–')[0].strip()
price_a.append(float(price))

dictionary_a = {"Product": product_a, "Price": price_a}
DataFrame_a = pd.DataFrame(dictionary_a)
return DataFrame_a

except Exception as e:
print(f"An error occurred: {e}")
return pd.DataFrame()

def create_chart():
global DataFrame_a
DataFrame_a = get_description()
DataFrame_a.plot.barh(x="Product", y="Price")
print("Horizontal bar chart has been created.")

def display_matrix():
global DataFrame_a
DataFrame_a = get_description()
print(DataFrame_a)

def save_to_excel():
global DataFrame_a
DataFrame_a = get_description()
file_name = text_box.get()
DataFrame_a.to_excel(file_name + "sofasofa.xlsx")
print('Matrix has been saved to Excel file "', file_name, '".')

MainForm = tkinter.Tk()
MainForm.title("Form_a")
MainForm.geometry("300x250")

Button1 = tkinter.Button(MainForm, text="Retrieve data", command=get_description)
Button1.pack()

Button2 = tkinter.Button(MainForm, text="Create chart", command=create_chart)
Button2.pack()

Button3 = tkinter.Button(MainForm, text="Display matrix", command=display_matrix)
Button3.pack()

Label = tkinter.Label(MainForm, text="Please enter filename:")
Label.pack()
text_box = tkinter.Entry(MainForm, width=25)
text_box.pack(pady=11)
Button4 = tkinter.Button(MainForm, text="Save to Excel", command=save_to_excel)
Button4.pack()

This above is the code
and the error is this:
Exception in Tkinter callback
Traceback (most recent call last):
File "\anaconda3\lib\tkinter\_init.py", line 1892, in __call_
return self.func(*args)
File "\Desktop\test.py", line 41, in create_chart
DataFrame_a.plot.barh(x="Product", y="Price")
File "anaconda3\lib\site-packages\pandas\plotting\_core.py", line 1216, in barh
return self(kind="barh", x=x, y=y, **kwargs)
File "anaconda3\lib\site-packages\pandas\plotting\core.py", line 972, in __call_
return plot_backend.plot(data, kind=kind, **kwargs)
File "anaconda3\lib\site-packages\pandas\plotting\matplotlib\init_.py", line 71, in plot
plot_obj.generate()
File "\anaconda3\lib\site-packages\pandas\plotting\_matplotlib\core.py", line 295, in generate
self._post_plot_logic(ax, self.data)
File "anaconda3\lib\site-packages\pandas\plotting\_matplotlib\core.py", line 1528, in _post_plot_logic
s_edge = self.ax_pos[0] - 0.25 + self.lim_offset
IndexError: index 0 is out of bounds for axis 0 with size 0


Răspuns :

Răspuns:

nu știu engleză sorystrebuse sasc