linux里面访问一个链接的方法

例如:

elinks --dump http://www.baidu.com
yum search elinks--如果没有这个工具,可查看是需要下载哪些包

2.wget 这个会将访问的首页下载到本地

[root@el5-mq2 ~]# wget http://www.baidu.com
--2011-10-17 16:30:10-- http://www.baidu.com/
Resolving www.baidu.com... 119.75.218.45, 119.75.217.56
Connecting to www.baidu.com|119.75.218.45|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8403 (8.2K) [text/html]
Saving to: `index.html'

100%[==========================================================================================>] 8,403 --.-K/s in 0.01s

2011-10-17 16:30:10 (648 KB/s) - `index.html' saved [8403/8403]

3.curl会显示出源码

curl http://www.baidu.com/index.html

4.lynx(这个以前在群里面见有人讨论过,但是没有尝试过,想用的话还需要下载软件)

lynx http://www.baidu.com

但是使用curl的时候传递多个参数的时候会出现问题;

  1. url 为 http://mywebsite.com/index.php?a=1&b=2&c=3
  2. web形式下访问url地址,使用 $_GET是可以获取到所有的参数
  3. curl -s http://mywebsite.com/index.php?a=1&b=2&c=3
  4. 然而在linux下,上面的例子 $_GET只能获取到参数 a
  5. 由于url中有&其他参数获取不到,在linux系统中 &会使进程系统后台运行
  6. 必须对 &进行下转义才能 $_GET获取到所有参数
  7. curl -s http://mywebsite.com/index.php?a=1&b=2&c=3
  8. 当然,最简单的方法 用双引号把整个url引起来就ok了
  9. curl -s "http://mywebsite.com/index.php?a=1&b=2&c=3"
  10. # 顺便再提一下 curl 中 post 传参数的方法
  11. curl -d 'name=1&pagination=2'demoapp.sinap.com/worker.php
  12. # 这样 demoapp.sinap.com 站点中的 worker.php 脚本,就能得到 $_POST['name'] 和 $_POST[''pagination] 对应的值
  13. # 再补充下curl获得网站信息的方法( -s 表示静默 --head 表示取得head信息 )
  14. curl -s --head www.sina.com

http://www.ruanyifeng.com/blog/2011/09/curl.html

猜你喜欢

转载自www.cnblogs.com/hanfe1/p/12706861.html