python3 spider 02 获取html的url、 head、 status

#coding:utf-8
from urllib import request
import chardet

if __name__=='__main__':
	req = request.Request('http://www.csdn.net')
	response = request.urlopen(req)
	#读取url信息
	url = response.geturl();
	print(url)
	#读取头信息
	info = response.info()
	print(info)
	code = response.getcode()
	print(code)

打印结果

---------- run python ----------
https://www.csdn.net/


Server: openresty
Date: Thu, 08 Nov 2018 16:38:59 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Set-Cookie: uuid_tt_dd=10_37029271700-1541695139580-132031; Expires=Thu, 01 Jan 2025 00:00:00 GMT; Path=/; Domain=.csdn.net;
Set-Cookie: dc_session_id=10_1541695139580.760940; Expires=Thu, 01 Jan 2025 00:00:00 GMT; Path=/; Domain=.csdn.net;
Vary: Accept-Encoding
Set-Cookie: uuid_tt_dd=9797795953525243556_20181109; expires=Sun, 05-Nov-2028 16:38:59 GMT; Max-Age=315360000; path=/; domain=csdn.net
Strict-Transport-Security: max-age=864000


200

Output completed (1 sec consumed) - Normal Termination
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值