小弟我最近在抓新聞網站資料
用BeautifulSoup
用print資料都正常
但是存成csv檔就是出不來
請大家幫幫忙
程式碼
import requests
import csv
from bs4 import BeautifulSoup
res = requests.get("https://tw.news.yahoo.com/politics/archive/")
soup = BeautifulSoup(res.text)
for item in soup.select('.txt'):
f = open("stock.csv","w")
w = csv.writer(f)
w.writerows((item.select('a')[0].text).encode('utf-8'))
f.close()