python3之requests

Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库。它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTTP 测试需求。Requests 的哲学是以 PEP 20 的习语为中心开发的,所以它比 urllib 更加 Pythoner。
python版本支持:python2.7 | 3.4 | 3.5 | 3.6 | 3.7
详见中文官方文档v2.18.1:http://docs.python-requests.org/zh_CN/latest/index.html

>>> import requests
>>> r = requests.get("https://www.baidu.com")
>>> r
<Response [200]>
>>> dir(r)
[
'__attrs__', '__bool__', '__class__', '__delattr__', '__dict__', '__dir__',
'__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', 
'__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', 
'__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', 
'__new__', '__nonzero__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__',
'__weakref__', '_content', '_content_consumed', '_next', 

'apparent_encoding', 'close', 'connection', 'content', 'cookies', 'elapsed', 
'encoding', 'headers', 'history', 'is_permanent_redirect', 'is_redirect', 
'iter_content','iter_lines', 'json', 'links', 'next', 'ok', 
'raise_for_status','raw', 'reason', 'request', 'status_code', 'text', 'url'
]
>>>
>>> r.status_code
200
>>> r.url
'https://www.baidu.com/'
>>> r.content
b'<!DOCTYPE html>\r\n<!--STATUS OK--><html>...
>>> r.encoding
'ISO-8859-1'
>>> r.encoding = 'utf-8'
>>> r.encoding
'utf-8'
>>> r.text
'<!DOCTYPE html>\r\n<!--STATUS OK--><html>...
>>> r.request
<PreparedRequest [GET]>
>>> r.reason
'OK'
>>> r.raw
<urllib3.response.HTTPResponse object at 0x000002444AEEC550>
>>> r.ok
True
>>> r.next
>>> 
>>> r.json
<bound method Response.json of <Response [200]>>
>>> r.links
{}
r.headers['content-type']
'text/html'
r.headers
{
'Cache-Control':'private,no-cache,no-store,proxy-revalidate,no-transform',
'Connection': 'Keep-Alive', 'Content-Encoding': 'gzip', 
'Content-Type': 'text/html', 'Date': 'Wed, 31 Oct 2018 01:00:38 GMT', 
'Last-Modified': 'Mon, 23 Jan 2017 13:24:49 GMT', 'Pragma': 'no-cache', 
'Server': 'bfe/1.0.8.18', 
'Set-Cookie': 'BDORZ=27315; max-age=86400; domain=.baidu.com; path=/', 
'Transfer-Encoding': 'chunked'}


Beautiful is better than ugly.(美丽优于丑陋)
Explicit is better than implicit.(清楚优于含糊)
Simple is better than complex.(简单优于复杂)
Complex is better than complicated.(复杂优于繁琐)
Readability counts.(重要的是可读性)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值