如何在PYSPIDER中设置同时请求数

问题描述 投票:0回答:1

我正在尝试使用Pyspider搜寻器来扫描我的网站,我希望每2秒发出一个请求,但是目前我知道同时发出3个请求,我找不到更改此设置的设置参数。

[我在/usr/lib/python2.7/site-packages/pyspider/scheduler/scheduler.py文件中找到了设置LOOP_INTERVAL,我将其设置为2(秒),但是现在每2秒发出3个请求,而我每2秒只希望1个请求。

Thi是我的设定:

from pyspider.libs.base_handler import *


class Handler(BaseHandler):
    crawl_config = {
    }

    @every(minutes=24 * 60)
    def on_start(self):
        self.crawl('https://example.com/', callback=self.index_page)

    @config(age=10 * 24 * 60 * 60)
    def index_page(self, response):
        for each in response.doc('a[href^="http"]').items():
            self.crawl(each.attr.href, callback=self.detail_page)

    @config(priority=2)
    def detail_page(self, response):
        return {
            "url": response.url,
            "title": response.doc('title').text(),
        }

然后,我还希望搜寻器仅深入1页,从哪里可以更改此参数?

python scrapy web-crawler pyspider
1个回答
0
投票

对于第一个问题,请尝试在settings.py(CONCURRENT_REQUESTS)中将see official documentation设置为1。

对于第二个问题,您可以在settings.py中将DEPTH_LIMIT设置为所需的深度。默认值为0,表示默认情况下不施加限制(see official documentation)。

© www.soinside.com 2019 - 2024. All rights reserved.