云计算之闲谈网页下载

别人的网页总是好的,下载下来我们自己用,那咋下载呢,方法有很多,闲谈一下,以下载百度首页为例。

方案1:wget

wget http://www.baidu.com/index.html -O index.html

方案2:curl

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

方案3:shell

vim get.sh
    #!/bin/bash
    exec 9<>/dev/tcp/www.baidu.com/80
    echo -ne "GET /index.html HTTP/1.1\r\n" >&9
    echo -ne "HOST: www.baidu.com\r\n\r\n" >&9
    cat <&9
chmod +x get.sh
./get.sh > index.html

方案4:python

vim get.py
    #!/usr/bin/python
    import httplib
    httpconn = httplib.HTTPConnection("www.baidu.com")
    httpconn.request("GET", "/index.html")
    resp = httpconn.getresponse()
    if resp.reason == "OK":
      resp_data = resp.read()
      print resp_data
      print len(resp_data)
    httpconn.close()
chmod +x get.py
./get.py  > index.html

还可以使用其他方案实现此功能,这里就不重复阐述了。

猜你喜欢

转载自blog.csdn.net/mx_steve/article/details/91351483