本文共 1505 字,大约阅读时间需要 5 分钟。
目录
curl官网下载地址:
为了实现在命令窗口的任意目录下使用curl命令:
1.给Windows增加curl命令的环境变量,增加CURL_HOME环境变量,给PATH环境变量加上%CURL_HOME%\bin;
或
2.下载后将ca-bundle.crt和curl.exe两个文件拷贝至C:\Windows\System32
打开命令行输入测试:(会有中文乱码)
Git中自带curl命令,我们只需要将其配置一下即可在windows命令行使用。
下载git for windows 工具软件:
安装除了一步需要注意的其它都点下一步即可,需要注意的是PATH环境选择界面,选择“Run Git from the Windows Command Prompt”
Git的环境变量会自动添加,如果发现环境变量PATH中没有,需要手动添加.
打开cmd命令提示符,运行命令(git --version)检查git 版本号,如果正确显示版本号说明安装正常.
安装完成后,在桌面右键鼠标就可看到git相关命令:
进入gitbash命令行窗口,输入
curl -V
使用curl爬取百度页面,命令如下:
curl http://www.baidu.com
-o output 保存页面内容到txt文本,命令如下:(自动解决中文乱码问题)
curl http://www.baidu.com -s -o 1.txt
在桌面生成了1.txt文件,查看内容,就是网页内容
在Git的安装目录下有个“mingw64”或者“mingw”文件夹,其实里面已经带有curl命令,但他只能在git-bash中运行,为了能在windows命令行也能调用该命令,可以在Git安装目录的cmd文件夹中新建一个curl.cmd文件,然后将以下内容复制进去即可:
@rem Do not use "echo off" to not affect any child calls.@setlocal @rem Get the abolute path to the parent directory, which is assumed to be the@rem Git installation root.@for /F "delims=" %%I in ("%~dp0..") do @set git_install_root=%%~fI@set PATH=%git_install_root%\bin;%git_install_root%\mingw\bin;%git_install_root%\mingw64\bin;%PATH%@rem !!!!!!! For 64bit msysgit, replace 'mingw' above with 'mingw64' !!!!!!! @if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%@if not exist "%HOME%" @set HOME=%USERPROFILE% @curl.exe %*
打开cmd 命令提示符,运行命令(curl –-version)检查curl版本号:
其实不仅仅curl命令可以这样,Git还自带了很多命令,也可以通过这种方式配置.