python urlopen返回的是啥类型_数据爬虫:urlopen返回的应答对象respose两个常用方法...

1.info()

这个是返回对象的字典对象,通常是服务器发送的特定的头。

import urllib.request

url="https://www.baidu.com"

respose=urllib.request.urlopen(url)

html_doc=respose.read().decode("utf-8")

print(respose.info())

运行结果:

C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/Administrator/PycharmProjects/untitled2/1-2.py

Accept-Ranges: bytes

Cache-Control: no-cache

Content-Length: 227

Content-Type: text/html

Date: Mon, 06 Aug 2018 05:45:03 GMT

Etag: "5b56b4a8-e3"

Last-Modified: Tue, 24 Jul 2018 05:10:00 GMT

P3p: CP=" OTI DSP COR IVA OUR IND COM "

Pragma: no-cache

Server: BWS/1.1

Set-Cookie: BD_NOT_HTTPS=1; path=/; Max-Age=300

Set-Cookie: BIDUPSID=FFBC03A7700100FA1362A08E8B484D6C; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com

Set-Cookie: PSTM=1533534303; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com

Strict-Transport-Security: max-age=0

X-Ua-Compatible: IE=Edge,chrome=1

Connection: clos

2. geturl()

import urllib.request

url="https://www.baidu.com/"

respose=urllib.request.urlopen(url)

print(respose.geturl())

运行结果:

C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/Administrator/PycharmProjects/untitled2/1-3.py

https://www.baidu.com/

Process finished with exit code 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值