我有一个包含 html/doc 文件列表的 txt 文件,我想使用 python 下载它们并将它们保存为 1.html、2.doc、3.doc、...
http://example.com/kran.doc
http://example.com/loj.doc
http://example.com/sks.html
我已经设法创建了功能齐全的脚本,除了 python 总是会在新创建的文件的末尾添加问号(如果你从 linux 看),如果你从 windows 看,文件名将类似于5CFB43~X
import urllib2
st = 1;
for line in open('links.txt', 'r'):
u = urllib2.urlopen(line)
ext = line.split(".")
imagefile = str(st)+"."+ext[-1]
#file created should be something.doc but its something.doc? -> notice question mark
fajl = open(imagefile, "w+")
fajl.write(u.read())
fajl.close()
print imagefile
st += 1