【发布时间】:2021-01-21 14:34:09
【问题描述】:
我正在尝试使用 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)
【问题讨论】:
-
拼写为
df.to_csv。
标签: python pandas dataframe selenium beautifulsoup