首先的声明我文档是对 http://lijunjie.iteye.com/blog/395270 博客的总结。
参考博客是:http://lijunjie.iteye.com/blog/395270
参考博客是:http://lijunjie.iteye.com/blog/395270
参考博客是:http://lijunjie.iteye.com/blog/395270
====================================== 重要的事情说三遍 ============================
我用的是windows所以没有像苹果那样内置curl,要去网站进行下载。网站地址:http://curl.haxx.se/,点击“Downloads”菜单,各种版本下载已经玲琅满目了。
根据的windows系统下载相应位数的版本,我是64位下载版本是Win64 - Generic下面的某一个版本,解压之后添加的到path下方便在命令行(DOS)中使用。
下面介绍以下各种参数的配合使用:
1,直接显示一个网页的源代码
>> curl http://www.baidu.com
2,将网页的源代码的保存到指定的文件中
>> curl http://www.baidu.com > D:\\baidu_index.html
或者使用参数 -o(区分大小写)同样的效果
>> curl -o D:\\baidu_index.html http://www.baidu.com
3,牛的来了,使用-D参数保存cookie信息到硬盘中
>> curl -o D:\\baidu_index.html -D D:\\baidu_index.txt http://www.baidu.com
同时,使用-b参数将cookie信息放到下一次请求的request中
>>curl -b D:\\baidu_index.txt http://www.baidu.com
4,使用-A参数,指定特定的浏览器进行访问网站
>> curl -A " Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)" http://www.baidu.com
5,使用-e参数,跳过服务器端常用的限制方法,检查http访问的referer。 引用(博客:http://lijunjie.iteye.com/blog/395270)的描述:你先访问首页,再访问里面所指定的下载页,这第二次访问的referer地址就是第一次访问成功后的页面地址。这样,服务器端只要发现对下载页面某次访问的referer地址不 是首页的地址,就可以断定那是个盗连了~~~~~
>>curl -e "www.baidu.com" http://map.baidu.com/ > D:\\baidu_index.html
====================================== 好玩的地方来了 ================================
6,使用Curl下载网页中的图片,同样是使用参数 -o 或者 -O 会将服务器的图片名称保存到本地
>> curl -o D:\\001.jpg http://p2.so.qhimg.com/t011af09b4219c78c7c.jpg
或者使用 -O,图片保存到当前执行命令的目录
>> curl -O http://p2.so.qhimg.com/t011af09b4219c78c7c.jpg
7,下载一系列的图片,可以使用文件名后增加 [0-10]
>> curl -O http://p2.so.qhimg.com/t01[0-10].jpg
8,下载文件重命名
#1是变量,指的是这部分,第一次取值zzh,第二次取值nick
#2代表的变量,则是第二段可变部分---[001-201],取值从001逐一加到201
>> curl -o #2_#1.jpg http://cgi2.tky.3web.ne.jp/~/[001-201].JPG
9,curl使用参数-r,分段下载数据。如果你用UNIX或苹果,用 cat zhao.part* > zhao.mp3就可以
如果用的是Windows,用copy /b 来解决吧,呵呵
>> curl -r 0-10240 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
>> curl -r 10241-20480 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
>>curl -r 20481-40960 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
>> curl -r 40961- -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3
10,下载ftp服务器数据
>> curl -u name:passwd ftp://ip:port/path/file
或者大家熟悉的
>> curl ftp://name:passwd@ip:port/path/file
11,使用-T 参数,执行FTP上传数据。如果是http使用-T使用put方法提交数据
>> curl -T localfile -u name:passwd ftp://upload_site:port/path/
12,http提交一个表单,比较常用的是POST模式和GET模式
get:
>> curl http://www.yahoo.com/login.cgi?user=nickwolfe&password=12345
post,使用参数-d
>> curl -d "user=nickwolfe&password=12345" http://www.yahoo.com/login.cgi
13,http post上传文件
>> curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi
14,最后看一下curl使用代理,-x参数
>> curl -x “代理IP:端口” http://www.google.com
这个东西很好玩,持续使用。以后有总结在发一篇