为什么我使用 curl 获得二进制输出

Ray*_*ndo 2 binary curl

不确定是否可以共享我试图获取其来源的网站,但我认为有必要进行更好的解释。如果不是提前,我深表歉意

命令: curl -k -L -s https://www.mi.com

由于出现以下错误,由于某种原因,输出是二进制数据

Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
Run Code Online (Sandbox Code Playgroud)

如何阅读页面 HTML 源代码?谢谢!

ter*_*don 10

只需将其重定向到一个文件,然后您就可以调查它是什么:

curl -k -L -s https://www.mi.com > outFile
Run Code Online (Sandbox Code Playgroud)

您现在可以使用该file命令查看outFile包含的内容:

$ file outFile 
outFile: gzip compressed data, from Unix, original size modulo 2^32 135402
Run Code Online (Sandbox Code Playgroud)

所以,您刚刚下载了压缩数据。要查看它,请解压缩:

mv outFile outFile.gz ## gzip requires the .gz extension
gunzip outFile.gz
Run Code Online (Sandbox Code Playgroud)

或者只是使用可以处理压缩数据的工具,例如zmore

zmore outFile
Run Code Online (Sandbox Code Playgroud)

或者zcat

zcat outFile
Run Code Online (Sandbox Code Playgroud)


Ste*_*itt 5

返回的数据是经过压缩的,可以curl通过添加--compressed选项指示直接处理解压:

curl -k -L -s --compressed https://www.mi.com
Run Code Online (Sandbox Code Playgroud)