我写了一个简单的python脚本:
#!/usr/bin/python
import sys
import urllib
if len(sys.argv) < 2:
print 'usage: python %s <file-urls>' % (sys.argv[0])
sys.exit(2)
print '%-15s %15s' % ('URL_PAGE', 'STATUS')
FileName = sys.argv[1]
InputFile = open(FileName)
for url in InputFile:
out = urllib.urlopen(url)
status = out.getcode()
print '%-15s %15s' % (url, status)
输出是这样的:
URL_PAGE STATUS
http://test.com
200
但我想要这个输出:
URL_PAGE STATUS
http://test.com 200
答案 0 :(得分:2)
strip
来自url
的换行符(以及无用的空格):
print '%-15s %15s' % (url.strip(), status)