【发布时间】:2013-07-21 05:11:49
【问题描述】:
我真的很难弄清楚如何打印到列表中。我想打印我指定的 URL 的服务器响应代码。您知道我将如何更改代码以将输出打印到列表中吗?如果没有,你知道我在哪里可以找到答案吗?我已经搜索了几个星期了。
代码如下:
import urllib2
for url in ["http://stackoverflow.com/", "http://stackoverflow.com/questions/"]:
try:
connection = urllib2.urlopen(url)
print connection.getcode()
connection.close()
except urllib2.HTTPError, e:
print e.getcode()
打印:
200
200
我想要:
[200, 200]
【问题讨论】:
标签: python list csv urllib2 urlopen