Python - 使用CSV编写器后CSV文件为空

时间:2015-12-03 01:32:20

标签: python csv

我是新手,我在网页编写中编写CSV文件时遇到了麻烦。有人可以帮忙吗?谢谢!

import sys
import urllib2
import csv
import requests 
from bs4 import BeautifulSoup

#web scraping wind data
r_wind = requests.get('http://w1.weather.gov/data/obhistory/KCQX.html')
html_wind = r_wind.text
soup = BeautifulSoup(html_wind, "html.parser")
table = soup.find('table')
rows_wind = table.findAll('tr')
rows_wind = rows_wind[1:]

#writing to a csv file
csvfile_wind = open("wind.csv","wb")
output_wind = csv.writer(csvfile_wind, delimiter=',',quotechar='"',quoting=csv.QUOTE_MINIMAL)
for row in rows_wind:
    Date = cells[0].text.strip()
    Time = cells[1].text.strip()
    Wind = cells[2].text.strip()
    output.writerow([Date,Time,Wind])
csvfile_wind.close()

0 个答案:

没有答案