日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python requests爬网页加速

發(fā)布時間:2023/12/18 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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爬网页加速的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。