我目前的实现是:
import csv
import urllib.request
from bs4 import BeautifulSoup
f=urllib.request.urlopen('<my_url_goes_here>')
soup = BeautifulSoup(f.read())
my_csv = csv.reader(soup.pre.text,delimiter=",")
for row in my_csv:
print(row)
我想以以下格式打印出我的数据:
//datestamp,SvcName,AvgSvcTime,MinSvcTime,MaxSvcTime,SvcVol
2013-03-19 00:00:00,cfmeqdequeue,1,0,10,198
2013-03-19 00:01:00,cfmeqdequeue,1,0,10,198
2013-03-19 00:02:00,cfmeqdequeue,1,0,10,198
但是,实际输出如下所示:
['c']
['f']
['m']
['e']
['q']
['d']
['e']
['q']
['u']
['e']
['u']
['e']
注意:soup.pre.text
打印以下内容并具有正确的换行符:
'\n//datestamp,SvcName,AvgSvcTime,MinSvcTime,MaxSvcTime,SvcVol\n2013-03-19 00:00:00,cfmeqdequeue,1,0,10,198\n2013-03-19 00:01:00,cfmeqdequeue,1,0,10,198\n
因此,当我使用 csv.reader() 或 for 循环时,一定有问题。