Terrii
Terrii

Reputation: 385

Python: 'curl' is not recognized as an internal or external command, operable program or batch file

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'

Upvotes: 3

Views: 912

Answers (1)

PearsonArtPhoto
PearsonArtPhoto

Reputation: 39698

Issues that I see:

  1. curl doesn't seem to be installed on your local machine. Not sure why you want to make a system call for only grabbing a URL anyways...
  2. As you don't have curl installed, then no final.txt was ever created. When you try to load it later on in the system, it doesn't work.

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. I'll copy a simple example from the python docs, and let you figure out how to use it from there. Note, there's a large difference on how to do this if you are using python 2 or 3, so just be warned...

>>> 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()

Upvotes: 1

Related Questions