[英]Python Downloading From URL Error?
can anyone see a problem with this code because it keeps comming back with an error and this is the code and ill post the error under the code... thanks for the help in advanced... 任何人都可以看到这个代码的问题,因为它一直回来一个错误,这是代码,并在代码下发布错误...感谢高级帮助...
import commands
import os
import pickle
def readDir():
directory = raw_input('In which folder would you like to save the files?? \n')
if(os.path.exists(directory)):
print 'Error!! Please give an other name '
directory = raw_input('In which folder would you like to save the file??\n')
os.mkdir(directory)
os.chdir(directory)
else:
os.mkdir(directory)
os.chdir(directory)
readDir()
url = raw_input('Which url are you aiming at ?\n')
tmp = open('tempo.txt','w');
tmp.writelines(url)
tmp.close()
tmp = open('tempo.txt','r');
link = tmp.read()
os.system(" curl " + link +"| egrep -o 'http:.*All\.ram' > final.txt ")
infile = open('final.txt', 'r')
outfile = open('tmp.txt', 'w')
for line in infile:
outfile = open('tmp.txt', 'w')
key = line
list = key.split("/")
dir = list[6]
outfile.writelines(key)
outfile.close()
open('tmp.txt','r')
os.system("cat tmp.txt | xargs -n1 -i curl {} > links")
os.system("wget -P %s -i links" %dir)
infile.close()
outfile.close()
os.remove(outfile.name)
os.remove('links')
os.remove(tmp.name)
Error: i just used google as an example. 错误:我只是以谷歌为例。
Which url are you aiming at ?
google.com
'curl' is not recognized as an internal or external command, operable program or batch file.
Traceback (most recent call last):
File "C:\Users\User\Desktop\download.py", line 52, in <module>
infile = open('final.txt', 'r')
IOError: [Errno 2] No such file or directory: 'final.txt'
Issues that I see: 我看到的问题:
Bottom line, find a way to do this without using curl, and you'll be better off. 最重要的是,找到一种方法来做到这一点,而不使用卷曲,你会更好。
os.system(" curl " + link +"| egrep -o 'http:.*All\.ram' > final.txt ")
Looking more closely, it looks like you just want to download the file. 仔细观察,看起来您只想下载该文件。 It's a lot easier to do this with a urllib directly. 使用urllib直接执行此操作要容易得多。 I'll copy a simple example from the python docs , and let you figure out how to use it from there. 我将从python文档中复制一个简单的例子,让你弄清楚如何从那里使用它。 Note, there's a large difference on how to do this if you are using python 2 or 3, so just be warned... 请注意,如果您使用的是python 2或3,如何执行此操作会有很大差异,所以请注意......
>>> import urllib
>>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
>>> f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query?%s" % params)
>>> print f.read()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.