簡體   English   中英

在Windows CMD中使用python中的wget或curl

[英]Use wget or curl from python in Windows CMD

我是Python的新手。 我在Windows上安裝了Python 3.7.3 ,並希望使用CMD來運行.py文件。

命令就像py xxx.py ,它實際上是從服務器下載一些文件。

當它詢問“可以下載”時,我點擊了肯定。

然后出現一條消息。

該腳本需要在系統上使用curl或wget,請在運行腳本之前先安裝它們!

該程序將退出。

但是當我嘗試運行pip install wget出現以下消息:

要求已經滿足:wget在c:\\ users \\ qin_l \\ appdata \\ local \\ programs \\ python \\ python37-32 \\ lib \\ site-packages(3.2)

當我輸入py -m wget xxx.file ,我可以下載文件(不是我想要的那個)

我猜不能通過窗戶的部分是

# Check if curl or wget commands exsit on your computer
if sys.version_info >= (3,0):
status_curl, result = subprocess.getstatusoutput('which curl')
status_wget, result = subprocess.getstatusoutput('which wget')
else:
status_curl, result = commands.getstatusoutput("which curl")
status_wget, result = commands.getstatusoutput("which wget")

並相應地

if status_curl == 0:
    cmd='curl -g "'+cmd+'" -o '+ ncout
  elif status_wget == 0:
    cmd='wget "'+cmd+'" -O '+ ncout
  else:
    sys.exit('\nThe script will need curl or wget on the system, please install them first before running the script !\nProgram will exit now !\n')

似乎wget可以在Python中工作,但不能在py文件中工作。 我在這里非常困惑。 我是否必須安裝Linux並在Ubuntu中運行命令?

您擁有的腳本希望將wgetcurl安裝為命令行工具,即。 您可以從CMD提示符運行它們。

令人困惑的是,還有一個名為wgetpython包 ,它與pip install wget一起pip install wget ,但它完全不同。

安裝命令行wget ,第一安裝使用Powershell的,然后安裝安裝wgetscoop install wget

我試圖將'哪個卷曲'更改為'curl'並且不再有錯誤消息。 但無法下載文件,因為“由於遇到錯誤而禁用SSL”。

轉向我必須在我的電腦中安裝Ubuntu,它終於有效了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM