Python-Requests (>= 1.*):如何禁用保持活动? [英] Python-Requests (>= 1.*): How to disable keep-alive?

查看:30
本文介绍了Python-Requests (>= 1.*):如何禁用保持活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Requests 模块编写一个简单的网络爬虫程序,我想知道如何禁用它的 -default-keep-alive 功能.

I'm trying to program a simple web-crawler using the Requests module, and I would like to know how to disable its -default- keep-alive feauture.

我尝试使用:

s = requests.session()
s.config['keep_alive'] = False

但是,我收到一条错误消息,指出会话对象没有属性config",我认为它已随新版本进行了更改,但我似乎无法在官方文档中找到如何操作.

However, I get an error stating that session object has no attribute 'config', I think it was changed with the new version, but i cannot seem to find how to do it in the official documentation.

其实我在一个特定的网站上运行爬虫,最多只能得到五个页面,然后无限循环,所以我认为这与keep-alive功能有关!

The truth is when I run the crawler on a specific website, it only gets five pages at most, and then keeps looping around infinitely, so I thought it has something to do with the keep-alive feature!

PS:Requests 是一个很好的网络爬虫模块吗?有什么更适合的吗?

PS: is Requests a good module for a web-crawler? is there something more adapted?

谢谢!

推荐答案

这个有效

s = requests.session()
s.keep_alive = False

在类似问题的评论中回答.

这篇关于Python-Requests (>= 1.*):如何禁用保持活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆