bash 您如何从终端获取网页源?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14419573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 23:14:53  来源:igfitidea点击:

How would you get a webpage source from Terminal?

macosbashterminal

提问by russellsayshi

On my website I have a text file with data on it (The site in question is hosted by GoDaddy, so I can't access the file locally). This file is updated through PHP. From the Unix/Linux/Mac bash I would like to get the contents of the text file so I can use it in scripts. Any help would be appreciated :)

在我的网站上,我有一个包含数据的文本文件(该网站由 GoDaddy 托管,因此我无法在本地访问该文件)。这个文件是通过 PHP 更新的。我想从 Unix/Linux/Mac bash 获取文本文件的内容,以便我可以在脚本中使用它。任何帮助,将不胜感激 :)

回答by Hassan

curlis installed already on your Mac, so you don't need to install it. You will also find curlinstalled on pretty much any Linux distribution. That's probably your safest bet.

curl已安装在您的 Mac 上,因此您无需安装它。您还会发现curl几乎所有 Linux 发行版上都安装了它。这可能是你最安全的选择。

cd ~/Desktop
curl www.google.com >> google.txt

wgetcan be installed on your Mac easily with Homebrew. It will likely be installed already on most Linux distributions.

wget可以使用Homebrew轻松安装在您的 Mac 上。它可能已经安装在大多数 Linux 发行版上。

cd ~/Desktop
wget www.google.com

回答by trojanfoe

Install MacPortsand install wget:

安装MacPorts并安装wget

$ sudo port install wget

And then:

进而:

$ wget http://godaddy.com/somewhere/somefile.txt

And the resulting text file will be somefile.txt(this can be changed using the -Ooption).

生成的文本文件将是somefile.txt(这可以使用该-O选项进行更改)。