2016-11-19 79 views
0
import urllib 
url = urllib.urlopen("http://chart.finance.yahoo.com/table.csv?\ 
s=%s&a=6&b=19&c=2016&d=9&e=18&f=2016&g=d&ignore=.csv").read() % ("GOOGL") 
print url 

上面的代码工作得很好,如果我在URL中输入GOOGL。当我尝试以字符串格式化时,为什么会出现此错误?不支持的格式字符

ValueError: unsupported format character '/' (0x2f) at index 319 

回答

1

% ("GOOGL")是错误的地方。你必须插入字符串

url = urllib.urlopen("http://chart.finance.yahoo.com/table.csv?\s=%s&a=6&b=19&c=2016&d=9&e=18&f=2016&g=d&ignore=.csv" % ("GOOGL")).read() 
+0

谢谢shaun! – lennisquinn