我是靠谱客的博主 过时月饼,这篇文章主要介绍python requests爬网页加速,现在分享给大家,希望可以做个参考。

import requests

req = requests.get(url)

一般用上述写法,访问网页久了会变卡,那么可以用下面方法替代

session = requests.Session()
req = session.get(url)

也就是说,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).

最后

以上就是过时月饼最近收集整理的关于python requests爬网页加速的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(95)

评论列表共有 0 条评论

立即
投稿
返回
顶部