search

Home  >  Q&A  >  body text

python - 爬虫没有按配置的时间运行,是为什么?

需求是这样,我把所有的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怎么配都感觉抓的不对,我理解问题?

大家讲道理大家讲道理2895 days ago241

reply all(5)I'll reply

  • PHPz

    PHPz2017-04-18 09:50:30

    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

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 09:50:30

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

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 09:50:30

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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:50:30

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

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 09:50:30

    Now I am studying to write a crawler in PHP

    reply
    0
  • Cancelreply