当前位置:网站首页>urllib的一个类型和六个方法
urllib的一个类型和六个方法
2022-07-22 18:45:00 【冲锋的禾】
前言: 通过urllib.request()获取的对象是类型是HttpReponse型的,针对这种类型,有六种常见的读取方法
一个类型:HttpResponse
六个方法:
read(): 读取所有字节
read(n): 读取n个字节
readline(): 读取一行
readline(): 按行读取,并且读取所有行
getcode(): 返回状态码
getur(): 返回url地址
getheaders(): 获取一个状态信息
具体实验代码:
import urllib.request
url = 'https://www.baidu.com'
#模拟浏览器给服务器发送请求
response = urllib.request.urlopen(url)
#一个类型和六个方法
# print(type(response))
# 读取多少个字节
# content = response.read()
# print(content)
#读取多少个字节
# content = response.read(5)
# print(content)
#读取一行
# content = response.readline()
# print(content)
# content = response.readlines()
# print(content)
#返回状态码
# print(response.getcode())
#返回的url地址
# print(response.geturl())
#获取是一个状态信息
# print(response.getheaders())
# 一个类型:HttpResponse
# 六个方法:read readline readlines getcode geturl getheaders
边栏推荐
猜你喜欢

线性回归与逻辑回归及其实现

Stack overflow basic exercise question - 3 (with a comparison of 32 and 64 bit differences)

Transformer

China's open source is moving towards the second tier!

Stack overflow basic exercise - 5 (string vulnerability)

After daily bookkeeping, the project chart shows various revenue and expenditure categories

如何为您的企业设置内部Wiki?

Linear regression and logical regression and their implementation

Globally and Locally Consistent Image Completion 论文笔记

How to configure a cute little shark theme for typera?
随机推荐
Sentence Bert + Milvus to realize intelligent question answering system
[SUCTF 2019]EasySQL
Globally and Locally Consistent Image Completion 论文笔记
Golang AES encryption and decryption
How to open win11 task manager? Skills and methods of opening win11 Task Manager
PWN stack overflow basic exercise - 2
lasso回归结果美化
PWN —— ret2libc1
[strong net cup 2019] casual note
Li Xiang, director of ZTE cloud infrastructure open source and standards: open source risks and open source governance for enterprises
Dedecms V5.7.97 contain an XSS vulnerability
Elementary analysis of graph convolution neural network (GCN)
IM即时通讯开发时手机信号为什么会差
安装不了schedule
Liu Jingjuan, Deputy Secretary General of the open atom open source foundation: Thoughts on the current situation and trend of open source development in China
R语言求导数
eNSP关于OSPF的综合实验
2019_ IJCAI_ Adapting BERT for Target-Oriented Multimodal Sentiment Classification
ciscn_ 2019_ n_ 1 - two solutions
centos7安装和卸载mysql5.7