gpt4 book ai didi

Python: 'curl' 不是内部或外部命令,也不是可运行的程序或批处理文件

转载 作者:行者123 更新时间:2023-11-28 18:50:28 24 4
gpt4 key购买 nike

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)

错误:我只是以谷歌为例。

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'

最佳答案

我看到的问题:

  1. curl 似乎没有安装在您的本地机器上。不确定为什么要进行系统调用只是为了抓取 URL...
  2. 因为您没有安装 curl,所以没有创建 final.txt。当您稍后尝试在系统中加载它时,它不起作用。

最重要的是,找到一种不使用 curl 来执行此操作的方法,你会过得更好。

os.system(" curl " + link +"| egrep -o 'http:.*All\.ram'  > final.txt  ")

仔细一看,您似乎只是想下载文件。直接使用 urllib 执行此操作要容易得多。我将从 python docs 中复制一个简单示例,并让您从那里弄清楚如何使用它。请注意,如果您使用的是 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()

关于Python: 'curl' 不是内部或外部命令,也不是可运行的程序或批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13777883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com