python requests爬网页加速
生活随笔
收集整理的這篇文章主要介紹了
python requests爬网页加速
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
import requestsreq = requests.get(url)
一般用上述寫法,訪問網(wǎng)頁久了會變卡,那么可以用下面方法替代
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爬网页加速的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: FFmpeg将多张图片合成视频
- 下一篇: Python进阶实战 1.0 :爬取豆瓣