問題描述:將爬取的資料儲存的csv檔案,遇到幾個問題,原始碼如下:

with open('F:\\Pythontest1\\douban.csv','w') as f:
     writer = csv.writer(f,dialect='excel')
     writer.writerow(['rank','title','rate','autor','member','quote'])
     for row in filmall:
           writer.writerow(row)

1.儲存檔案亂碼問題:

UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 46: illegal multibyte sequence

解決方法,with open('F:\\Pythontest1\\douban.csv','w',encoding='gb18030') as f

2.儲存的csv檔案,表格中間隔有空行問題:

解決方法,

with open('F:\\Pythontest1\\douban.csv','w',encoding='gb18030',newline='') as f: