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

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))
主站蜘蛛池模板: 沽源县| 咸阳市| 六安市| 邹平县| 周口市| 梅河口市| 玛多县| 当涂县| 宜宾市| 麻江县| 名山县| 襄樊市| 贵溪市| 留坝县| 加查县| 申扎县| 赤壁市| 富民县| 神农架林区| 岱山县| 泸水县| 会昌县| 长子县| 城固县| 横峰县| 乌鲁木齐县| 鹤壁市| 肃北| 南漳县| 石屏县| 聊城市| 鞍山市| 江油市| 南澳县| 灌云县| 丹巴县| 松原市| 涡阳县| 梅州市| 崇信县| 冀州市|