From 4fa2d68d235fabaf86ed600141cf84a69460f2e4 Mon Sep 17 00:00:00 2001 From: kakashitheaf Date: Mon, 13 Jun 2016 16:42:15 +0000 Subject: [PATCH] write result to file. --- douyu/douyu/items.py | 6 ++++-- douyu/douyu/spiders/spider.py | 24 +++++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/douyu/douyu/items.py b/douyu/douyu/items.py index c18cc83..9c7ec0f 100644 --- a/douyu/douyu/items.py +++ b/douyu/douyu/items.py @@ -7,5 +7,7 @@ class douyuItem(Item): # define the fields for your item here like: - name = Field() - + url = Field() + room_name = Field() + people_count = Field() + tag = Field() diff --git a/douyu/douyu/spiders/spider.py b/douyu/douyu/spiders/spider.py index cbd5e41..ca3e72e 100644 --- a/douyu/douyu/spiders/spider.py +++ b/douyu/douyu/spiders/spider.py @@ -36,13 +36,27 @@ class douyuSpider(CommonSpider): 'room_name': 'a::attr(title)', 'tag': 'span.tag.ellipsis::text', 'people_count': '.dy-num.fr::text' - } - } + } + } + + list_css_rules_for_item = { + '#live-list-contentbox li': { + '__use': '1', + '__list': '1', + 'url': 'a::attr(href)', + 'room_name': 'a::attr(title)', + 'tag': 'span.tag.ellipsis::text', + 'people_count': '.dy-num.fr::text' + } + } def parse_1(self, response): info('Parse '+response.url) - x = self.parse_with_rules(response, self.list_css_rules, dict) - print(json.dumps(x, ensure_ascii=False, indent=2)) + #x = self.parse_with_rules(response, self.list_css_rules, dict) + x = self.parse_with_rules(response, self.list_css_rules_for_item, douyuItem) + print(len(x)) + # print(json.dumps(x, ensure_ascii=False, indent=2)) # pp.pprint(x) - # return self.parse_with_rules(response, self.css_rules, douyuItem) + # return self.parse_with_rules(response, self.list_css_rules, douyuItem) + return x