| 12 | |
| 13 | |
| 14 | class TestMongo(feapder.AirSpider): |
| 15 | __custom_setting__ = dict( |
| 16 | ITEM_PIPELINES=["feapder.pipelines.mongo_pipeline.MongoPipeline"], |
| 17 | MONGO_IP="localhost", |
| 18 | MONGO_PORT=27017, |
| 19 | MONGO_DB="feapder", |
| 20 | MONGO_USER_NAME="", |
| 21 | MONGO_USER_PASS="", |
| 22 | ) |
| 23 | |
| 24 | def start_requests(self): |
| 25 | yield feapder.Request("https://www.baidu.com") |
| 26 | |
| 27 | def parse(self, request, response): |
| 28 | title = response.xpath("//title/text()").extract_first() # 取标题 |
| 29 | for i in range(10): |
| 30 | item = Item() # 声明一个item |
| 31 | item.table_name = "test_mongo" |
| 32 | item.title = title + str(666) # 给item属性赋值 |
| 33 | item.i = i + 5 |
| 34 | item.c = "777" |
| 35 | yield item # 返回item, item会自动批量入库 |
| 36 | |
| 37 | |
| 38 | if __name__ == "__main__": |