python - 爬虫没有按配置的时间运行,是为什么?
大家讲道理
大家讲道理 2017-04-18 09:48:30
0
5
236

需求是这样,我把所有的url存在了mongo库,想每天查一遍url,抓一遍数据,可是周末并没有执行,


这个项目的日志

项目配置是这样的,我修改过几次itag,让项目重跑,别的项目也遇到几天不跑

 @every(minutes=10)
    def on_start(self):
        """运行入口"""
        self.crawl('data:, on_crawl_A', callback=self.crawl_A)
        
    @config(age=60,priority=3)     
    def crawl_A(self, response):
        for page in range(1, 549):
            params = {
                'page_index': page, 'size': self.PAGE_SIZE,
                'source': 'aaa',
            }
            self.crawl(self.DATA_SERVICE_URL, params=params,
                       callback=self.query_local_api, timeout=60, proxy=False)

    @config(age=2 * 60,priority=3)
    def query_local_api(self, response):
        data = json.loads(response.text)
        if data['msg'] != 'Success':
            return
        urls = [url for url in data['body'] if url.startswith("http://")]
        print 'urls len------>{}'.format(len(urls))
        for url in urls:
            self.crawl(url, callback=self.detail_page)
    @config(age=3 * 60 * 60,priority=10)
    def detail_page(self, response):

其中query_local_api 是查询本地mongo接口返回url,其实我想这样配置

@config(age=24 * 60 * 60,priority=10)
    def detail_page(self, response):

但是发现这个age怎么配都感觉抓的不对,我理解问题?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(5)
PHPzhong
  1. Your code is inconsistent with the picture you posted. The code is run every 10 minutes, but the picture above is 6 hours

  2. Just find a task that you think should be included, get the taskid on the debug page (it’s in the json on the upper left), and go to the /task/project:taskid page to check its current status

大家讲道理

I am currently studying how to write scheduled tasks in Python. You may consider using apscheduler

刘奇

In fact, you can take a step back and look at it. This problem can be solved by using *nix系统自带的crontabplanned tasks

洪涛

Guess:
Could it be because the decorator you wrote is not handled correctly?

小葫芦

Now I am studying to write a crawler in PHP

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template