Python爬虫进阶-curl的使用

本笔记是爬虫进阶的第一篇,关于本系列笔记的介绍,请看Python爬虫进阶-前言。

本篇也是爬虫三大环节:数据获取、数据解析、数据存储中的第一个环节数据获取的首篇,主要介绍curl。了解curl,有助于我们快速查看一些站点信息。

curl 是一般linux发行版中都带有的小工具,利用这个工具可以很方便的发送网络请求,可以使用这个工具来查看某个页面相应的HTTP头信息。如果使用过php,应该也对curl不陌生。

在Windows系统中一样可以使用这个工具,在https://curl.haxx.se/download.html 选择不带SSL的版本(推荐),下载完成后解压到windows/system32目录。参考下载地址如下:http://www.paehl.com/open_source/?download=curl_754_0.zip

查看http头信息 curl -I www.zhihu.com

注意参数时大写的 I


C:\Users\yoo>curl -I www.zhihu.com
HTTP/1.1 301 Moved Permanently
Date: Thu, 20 Jul 2017 02:59:59 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Set-Cookie: aliyungf_tc=AQAAALkuSRFY/wEApMzf3br6Jf4nDnPk; Path=/; HttpOnly
Location: https://www.zhihu.com/
X-Req-ID: 1AEFFD4559701CAE
Server: ZWS
Vary: Accept-Encoding

查看http头及源码 curl -i www.zhihu.com

注意参数时小写的 i


C:\Users\yoo>curl -i www.zhihu.com
HTTP/1.1 301 Moved Permanently
Date: Thu, 20 Jul 2017 02:57:49 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Set-Cookie: aliyungf_tc=AQAAAI2NYj6jAwQApMzf3eIyR9eYkYXw; Path=/; HttpOnly
Location: https://www.zhihu.com/
X-Req-ID: 1A752B2C59701C25
Server: ZWS
Vary: Accept-Encoding


301 Moved Permanently

301 Moved Permanently



nginx



curl更多用法,可以参考:http://www.ruanyifeng.com/blog/2011/09/curl.html

你可能感兴趣的:(Python爬虫进阶-curl的使用)