官术网_书友最值得收藏!

There's more...

Requests and urllib3 are very similar in terms of capabilities. it is generally recommended to use Requests when it comes to making HTTP requests. The following code example illustrates a few advanced features: 

import requests

# builds on top of urllib3's connection pooling
# session reuses the same TCP connection if
# requests are made to the same host
# see https://en.wikipedia.org/wiki/HTTP_persistent_connection for details
session
= requests.Session()

# You may pass in custom cookie
r = session.get('http://httpbin.org/get', cookies={'my-cookie': 'browser'})
print(r.text)
# '{"cookies": {"my-cookie": "test cookie"}}'

# Streaming is another nifty feature
# From http://docs.python-requests.org/en/master/user/advanced/#streaming-requests
# copyright belongs to reques.org
r = requests.get('http://httpbin.org/stream/20', stream=True)

for line in r.iter_lines():
# filter out keep-alive new lines
if line:
decoded_line = line.decode('utf-8')
print(json.loads(decoded_line))
主站蜘蛛池模板: 广昌县| 汉源县| 疏附县| 琼结县| 阿合奇县| 太康县| 恩施市| 淮南市| 林甸县| 和静县| 三江| 泾源县| 福安市| 浦北县| 金门县| 黄梅县| 鄂尔多斯市| 无为县| 望都县| 巴林左旗| 翁牛特旗| 岢岚县| 东平县| 千阳县| 新兴县| 安福县| 潮州市| 夏河县| 上虞市| 郑州市| 沧州市| 临高县| 文山县| 曲靖市| 沙洋县| 望奎县| 文安县| 化德县| 敦化市| 蒲城县| 禹城市|