我正在尝试从网址下载文件。
我发现wget
命令能够做到这一点。由于我使用Jupyter,所以我不想使用pip
,但是conda install conda wget
无效,因为默认存储库中没有Windows wget
。因此,我做了conda install menpo wget
,成功安装了wget
。但是,我仍然无法在JupyterLab中导入wget
:
ModuleNotFoundError: No module named 'wget'
wget
的步骤?答案 0 :(得分:3)
在 Google-Collab 中,此代码运行良好:
!wget https://audio-previews.elements.envatousercontent.com/files/6319559/preview.mp3 -O sample_f.mp3
!wget https://audio-previews.elements.envatousercontent.com/files/256324900/preview.mp3 -O sample_m.mp3
但不在 Windows 10 本地。在我的 Jupyter Notebook 单元中,此代码:
# pip install wget
!python -m wget https://audio-previews.elements.envatousercontent.com/files/6319559/preview.mp3 -o sample_f.mp3
!python -m wget https://audio-previews.elements.envatousercontent.com/files/256324900/preview.mp3 -o sample_m.mp3
保存文件并返回:
Saved under sample_f.mp3
Saved under sample_m.mp3
或者我尝试了另一种方法:我从 "gcloud iot devices list" command 下载了适用于 Windows 的 wget.exe 并将其移动到 PATH 目录。然后代码也可以工作:
!wget https://audio-previews.elements.envatousercontent.com/files/6319559/preview.mp3 -O sample_f.mp3
!wget https://audio-previews.elements.envatousercontent.com/files/256324900/preview.mp3 -O sample_m.mp3
答案 1 :(得分:0)
正如Trenton_M所指出的,有一个urlib
库可以代替wget
来做到这一点:
import urllib.request
url-variable = 'https://adress'
urllib.request.urlretrieve(url, filename-variable)