代码如下:
import urllib.request
import importlib,sys
importlib.reload(sys)
#img.txt里的链接: http://static.animetaste.net/wp-content/uploads/2015/08/标题.jpg
x = 1
with open('img.txt', 'r') as f:
while 1:
link = f.readline()
if not link:
break
f1 = open("1"+".jpg", 'wb')
f1.write((urllib.request.urlopen(link)).read())
f1.close()
# urllib.request.urlretrieve(link,'D:/share folder/tutorial/img/%s.jpg' % x) 方法2,也不行
环境python3,所以reload(sys)那个方法就用不上了,另外我看了网上的一些答案,对中文逐个quote不现实,我要处理成百上千的不同的链接,每个链接都不一样的。请教一下各位有没有什么办法能把这种带中文的图片链接的图片下下来,最好直接来个能跑的代码,这工作量也很小的。万恶的中文啊,说好的python3没中文毛病的呢orz