如何使用wget读取基于https的数据?

问题描述

我正在尝试在Windows 10系统中使用Anaconda 3(conda 4.8.4)在jupyter笔记本中训练线性回归模型。当我尝试使用程序wget读取训练数据(来自“ https”网站的csv文件)时,出现错误

'wget' is not recognized as an internal or external command,operable program or batch file

我实际上已经在Anaconda提示符和jupyter笔记本终端中安装了该程序,但是仍然出现此错误。有谁知道如何解决这个问题?

这是我的代码

! wget https://github.com/dataprofessor/data/raw/master/BostonHousing.csv

enter image description here

解决方法

我认为您应该使用python工具而不是外部工具。使用起来更容易,并且您可以采用python及其库期望的方式提取数据。

这样简单的事情应该起作用:

import requests

# Get data using a GET request
r = requests.get('https://github.com/dataprofessor/data/raw/master/BostonHousing.csv')

# Continue proccesing and prepare for neural network.

# Here I print the data recvied to stdout as an example. You can just as easly write to a file or anything else you like

print(r.content)

或者,因为您已经安装了wget模块,所以可以像这样python -m wget "https://github.com/dataprofessor/data/raw/master/BostonHousing.csv"

来调用它