curl

Linux 下的这些小工具实在是太有用了。一个个顺手的工具,用shell脚本连接起来就是个强大的工具。

curl,居然可以模拟浏览器。

-b/–cookie   发送保存的cookie给浏览器。
-c/–cookie-jar 保存浏览器发给的cookie。

#curl -c cookie www.baidu.com
#more cookie

# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

.baidu.com      TRUE    /       FALSE   4294967295      BAIDUID C5AE008C713292B6C59FEDACE943B674:FG=1

-D/–dump-header   保存协议的头文件。
例如:
#curl -D httpheader www.baidu.com
# more httpheader

HTTP/1.1 200 OK
Date: Fri, 15 May 2009 07:28:46 GMT
Server: BWS/1.0
Content-Length: 3397
Content-Type: text/html
Cache-Control: private
Expires: Fri, 15 May 2009 07:28:46 GMT
Set-Cookie: BAIDUID=64C51BDDA94E78B1B88D0D5203269E9C:FG=1; expires=Fri, 15-May-39 07:28:46 GMT; path=/; domai
n=.baidu.com
P3P: CP=" OTI DSP COR IVA OUR IND COM "

-d/–data
例子:

curl -s -d "ip=www.baidu.com&action=2" 
> http://www.ip138.com/ips.asp
> |iconv -f gb2312 -t utf-8
> |grep 'ul class="ul1"'
> |sed -e 's/^.*">
  • /t/' -e 's/
  • /nt/g' -e 's/<.*$//'
  • 提交一个表单,而且这个表单是个POST请求。如果是GET,可直接加在url的后面。
    eg:
    在百度查询sunliguo:

    curl www.baidu.com/s?wd=sunliguo

    请选择你看完该文章的感受:

    不错 超赞 无聊 扯淡 不解 路过

    随机文章:

    发表评论