As my code works fine but on saving to CSV it gives me an error of Data frame Also gave me on Start of Code error <csv.DictReader object at 0x000001B5CCE8D240> [] even the name of the file is different that's multiple.py in which I uninstall/install Pandas library also but nothing is solved yet.
import requests
from bs4 import BeautifulSoup
import time
import pandas as pd
def Gucci(url):
headers={
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.79 Safari/537.36'}
r=requests.get(url,headers=headers)
soup = BeautifulSoup(r.content, 'html.parser')
content = soup.find_all('a',class_='product-tiles-grid-item-link js-ga-track')
time.sleep(6)
for items in content:
Title=items.find('div',class_='product-tiles-grid-item-info').h2.text
price=items.find('p',class_='price').span.text.replace("CHF", "")
Store='GUCCI'
Product_Type='Coat'
Category= 'Mens'
Country='Switzerland'
#print(Title,price,Store,Product_Type,Category)
skechers={
'Product_Name':Title,
'Product_Price': price,
'Store':Store,
'Product_Type':Product_Type,
'Category': Category,
'Country':Country
}
skechersshoes.append(skechers)
df = pd.DataFrame(skechersshoes)
#print(df.head())
print('ALL DONE ')
df.to_csv('Gucci.csv')
print('Saved to csv file')
return
Gucci('https://www.gucci.com/ch/en_gb/ca/men/ready-to-wear-for-men/coats-for-men-c-men-readytowear-coats')
