示例#1
0
 def test_constructor_meta_argument(self):
     req = Request()
     self.assertEqual(req.meta, {})
     req = Request(meta=1)
     self.assertEqual(req.meta, 1)
     req = Request(meta={'place': 'hell'})
     self.assertEqual(req.meta, {'place': 'hell'})
示例#2
0
 def task_generator(self):
     yield Request('test',
                   url=server.get_url(),
                   timeout=0.1,
                   meta={'id': 1})
     yield Request('test',
                   url=server.get_url(),
                   timeout=0.5,
                   meta={'id': 2})
示例#3
0
    def test_constructor_arguments(self):
        req = Request()
        self.assertEqual(req.tag, None)
        self.assertEqual(req.url, None)
        self.assertEqual(req.callback, None)

        req = Request('TAG')
        self.assertEqual(req.tag, 'TAG')
        self.assertEqual(req.url, None)

        req = Request('TAG', 'URL')
        self.assertEqual(req.tag, 'TAG')
        self.assertEqual(req.url, 'URL')

        req = Request(url='URL', tag='TAG')
        self.assertEqual(req.tag, 'TAG')
        self.assertEqual(req.url, 'URL')
示例#4
0
    def test_single_request(self):
        class SimpleCrawler(Crawler):
            data = {}

            def handler_test(self, req, res):
                self.data['response'] = res.body

        token = 'Python'
        self.server.response['data'] = token

        bot = SimpleCrawler()
        bot.add_task(Request('test', url=self.server.get_url()))
        bot.run()
        self.assertEquals(token, bot.data['response'])
示例#5
0
 def task_generator(self):
     yield Request('test', url=server.get_url(), meta={'id': 1})
示例#6
0
 def handler_test2(self, req, res):
     self.points.append(req.meta['id'])
     yield Request('test3', url=server.get_url(), meta={'id': 3})
示例#7
0
 def task_generator(self):
     for url in self._urls_todo:
         yield Request('test', url=url)
示例#8
0
 def task_generator(self):
     for x in range(10):
         yield Request('test', url=server.get_url())
示例#9
0
 def task_generator(self):
     yield Request('test', url=server.get_url())
示例#10
0
文件: demo.py 项目: sunilsharma07/iob
 def task_generator(self):
     for host in islice(open('var/domains.txt'), 20):
         host = host.strip()
         if host:
             yield Request('http://%s/' % host, tag='page')
示例#11
0
 def task_generator(self):
     yield Request('test', url=server.get_url(),
                   callback=self.handler_test)