|
@@ -40,33 +40,31 @@ class YcsdSpider(scrapy.Spider):
|
|
|
def parse3(self, response):
|
|
|
res = response.text
|
|
|
res = self.json_encode(res)
|
|
|
- if res['code'] == 200:
|
|
|
- for chapter in res['data']:
|
|
|
- chapter['bid'] = response.meta['bid']
|
|
|
- bid = response.meta['book_id']
|
|
|
- url = self.base_url + 'method=chapter&bid={}&cid={}'.format(bid, chapter['chapter_id'])
|
|
|
- yield scrapy.Request(url, meta=chapter, callback=self.parse4)
|
|
|
+ for chapter in res['data']:
|
|
|
+ chapter['bid'] = response.meta['bid']
|
|
|
+ bid = response.meta['book_id']
|
|
|
+ url = self.base_url + 'method=chapter&bid={}&cid={}'.format(bid, chapter['chapter_id'])
|
|
|
+ yield scrapy.Request(url, meta=chapter, callback=self.parse4)
|
|
|
|
|
|
def parse4(self, response):
|
|
|
res = response.text
|
|
|
res = self.json_encode(res)
|
|
|
- if res['code'] == 200:
|
|
|
- mysql = msyqlHelper()
|
|
|
- meta = response.meta
|
|
|
- data = dict()
|
|
|
- data['bid'] = meta['bid']
|
|
|
- data['name'] = meta['chapter_name']
|
|
|
- data['sequence'] = meta['chapter_order_number'] + 1
|
|
|
- data['size'] = len(res['data']['chapter_content'])
|
|
|
- data['is_vip'] = meta['chapter_need_pay']
|
|
|
- data['prev_cid'] = 0
|
|
|
- data['next_cid'] = 0
|
|
|
- data['recent_update_at'] = time.strftime("%Y-%m-%d %H:%M:%S",
|
|
|
- time.localtime(meta['chapter_last_update_time']))
|
|
|
- data['content'] = res['data']['chapter_content']
|
|
|
- data['ly_chapter_id'] = res['data']['chapter_id']
|
|
|
- mysql.inseraAll(data)
|
|
|
- mysql.close()
|
|
|
+ mysql = msyqlHelper()
|
|
|
+ meta = response.meta
|
|
|
+ data = dict()
|
|
|
+ data['bid'] = meta['bid']
|
|
|
+ data['name'] = meta['chapter_name']
|
|
|
+ data['sequence'] = meta['chapter_order_number'] + 1
|
|
|
+ data['size'] = len(res['data']['chapter_content'])
|
|
|
+ data['is_vip'] = meta['chapter_need_pay']
|
|
|
+ data['prev_cid'] = 0
|
|
|
+ data['next_cid'] = 0
|
|
|
+ data['recent_update_at'] = time.strftime("%Y-%m-%d %H:%M:%S",
|
|
|
+ time.localtime(meta['chapter_last_update_time']))
|
|
|
+ data['content'] = res['data']['chapter_content']
|
|
|
+ data['ly_chapter_id'] = res['data']['chapter_id']
|
|
|
+ mysql.inseraAll(data)
|
|
|
+ mysql.close()
|
|
|
|
|
|
def json_encode(self, jsonstr):
|
|
|
return json.loads(jsonstr)
|