AttributeError: 'DataFrame' 对象没有属性 'to_CSV'

时间:2021-01-21 14:34:09

标签: python pandas dataframe selenium beautifulsoup

我正在尝试使用 df.to_CSV 将我提取的 chrome 数据存储为 csv 格式

这是我的代码:

content = driver.page_source
soup = BeautifulSoup(content)
for a in soup.findAll('a',href=True, attrs={'class':'_13oc-S'}):
    name=a.find('div', attrs={'class':'_4rR01T'})
    price=a.find('div', attrs={'class':'_30jeq3 _1_WHN1'})
    rating=a.find('div', attrs={'class':'hGSR34 _2beYZw'})
    products.append(name.text)
    prices.append(price.text)
    ratings.append(rating.text)
df = pd.DataFrame({'Product Name':products, 'Price':prices, 'Rating':ratings})
df.to_CSV(r'C:\Users\Krea\Documents\products.csv', index=False)

2 个答案:

答案 0 :(得分:1)

区分大小写,应该是df.to_csv(...)

答案 1 :(得分:1)

Python 区分大小写。将最后一行更改为:

df.to_csv(r'C:\Users\Krea\Documents\products.csv', index=False)
相关问题