困惑的csv阅读拆分一切

时间:2013-09-03 23:05:15

标签: python csv python-2.7 urllib2

我有以下代码。

from urllib2 import urlopen
from csv import reader

up_url = "http://finviz.com/export.ashx?v=111&f=ind_stocksonly,sh_price_o10,ta_change_u,ta_changeopen_u,ta_highlow20d_nh,ta_highlow50d_nh,ta_highlow52w_nh,ta_sma20_pa,ta_sma200_pa,ta_sma50_pa&ft=4&o=-change"
up_text = urlopen(up_url).readline()
for row in reader(up_text):
    print row

所以我期待的是:

["No.","Ticker","Company","Sector","Industry","Country","MarketCap","P/E","Price","Change","Volume"]

['No.']
['', '']
['Ticker']
['', '']
['Company']
['', '']
['Sector']
['', '']
['Industry']
['', '']
['Country']
['', '']
['Market Cap']
['', '']
['P/E']
['', '']
['Price']
['', '']
['Change']
['', '']
['Volume']
[]
[]

据我了解,csv应该通过'\ n'然后按','分割字符串来创建列表。那么这里发生了什么?

1 个答案:

答案 0 :(得分:2)

从一行中删除.readline()方法:

up_text = urlopen(up_url)