如题,按照网上的例子写了个on_result,如下
def on_result(self, result):
con=MongoClient('mongodb://localhost:27017')
resultdb=con.spider
resultcollection=resultdb.resultdb
if result:
r={"project":"demo","result":result}
resultcollection.insert_one(r)
但是有报错:
track.process 14.26ms 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.
[E 160112 13:20:03 base_handler:194] 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/pyspider-0.3.6-py2.6.egg/pyspider/libs/base_handler.py", line 192, in run_task
self._run_func(self.on_result, result, response, task)
File "/usr/lib/python2.6/site-packages/pyspider-0.3.6-py2.6.egg/pyspider/libs/base_handler.py", line 149, in _run_func
return function(*arguments[:len(args) - 1])
File "<dem>", line 47, in on_result
File "/usr/lib64/python2.6/site-packages/pymongo/collection.py", line 1773, in __call__
self.__name.split(".")[-1])
TypeError: 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.
{
"exception": "'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.",
"follows": 0,
"logs": "[E 160112 13:20:03 base_handler:194] 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.\n Traceback (most recent call last):\n File \"/usr/lib/python2.6/site-packages/pyspider-0.3.6-py2.6.egg/pyspider/libs/base_handler.py\", line 192, in run_task\n self._run_func(self.on_result, result, response, task)\n File \"/usr/lib/python2.6/site-packages/pyspider-0.3.6-py2.6.egg/pyspider/libs/base_handler.py\", line 149, in _run_func\n return function(*arguments[:len(args) - 1])\n File \"<dem>\", line 47, in on_result\n File \"/usr/lib64/python2.6/site-packages/pymongo/collection.py\", line 1773, in __call__\n self.__name.split(\".\")[-1])\n TypeError: 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.\n",
"ok": false,
"result": "{'category",
"time": 0.014256954193115234
}
请大侠帮我解答下,谢谢
闭关修行中......