用 session , requests.Session()自带连接池,连接复用等等功能。
The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance, and will use urllib3 ‘ s connection pooling. So if you ’ re making several requests to the same host, the underlying TCP connection will be reused, which can result in a significant performance increase (see HTTP persistent connection).
s = requests.Session()
s.get('
http://example.com/aaa')
s.get('
http://example.com/bbb')
s.get('
http://example.com/ccc')
这么用下去就好,方法、参数和 requests 一样。