banquanmao.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. # -*- coding: utf-8 -*-
  2. import time
  3. from content_spider.baseSpider import baseSpider
  4. from content_spider.pipelines import formatcontent
  5. from content_spider.baseSpider import baseUpdateSpider
  6. from content_spider.baseSpider import fixChapterSpider
  7. from content_spider.baseSpider import baseUpdateBookStatusSpider
  8. import json
  9. from content_spider.Util import md5
  10. name = 'banquanmao'
  11. allowed_domains = ['api.banquanmao.com.cn']
  12. source = 'zy_banquanmao'
  13. source_name = 'zy_banquanmao版权猫'
  14. source_id = 38
  15. base_url = 'http://api.banquanmao.com.cn/channel/custom/zhiyu/BookSource?method={}&channelkey={}'
  16. doc = '''
  17. 大推_植宇
  18. 书籍列表:
  19. http://api.banquanmao.com.cn/channel/custom/zhiyu/BookSource?method=booklist&channelkey=ea1a4a2b760f1f385bc43b39abd0c6e0
  20. 书籍详情:
  21. http://api.banquanmao.com.cn/channel/custom/zhiyu/BookSource?method=bookinfo&channelkey=ea1a4a2b760f1f385bc43b39abd0c6e0&bid=6109
  22. 章节列表:
  23. http://api.banquanmao.com.cn/channel/custom/zhiyu/BookSource?method=chapterlist&channelkey=ea1a4a2b760f1f385bc43b39abd0c6e0&bid=6109
  24. 章节内容:
  25. http://api.banquanmao.com.cn/channel/custom/zhiyu/BookSource?method=chapter&channelkey=ea1a4a2b760f1f385bc43b39abd0c6e0&bid=6109&cid=1021506
  26. 来量_植宇
  27. 书籍列表:
  28. http://api.banquanmao.com.cn/channel/custom/zhiyu/BookSource?method=booklist&channelkey=6916f4f59737e43d43faeecb759b5e34
  29. 书籍详情:
  30. http://api.banquanmao.com.cn/channel/custom/zhiyu/BookSource?method=bookinfo&channelkey=6916f4f59737e43d43faeecb759b5e34&bid=6109
  31. 章节列表:
  32. http://api.banquanmao.com.cn/channel/custom/zhiyu/BookSource?method=chapterlist&channelkey=6916f4f59737e43d43faeecb759b5e34&bid=6109
  33. 章节内容:
  34. http://api.banquanmao.com.cn/channel/custom/zhiyu/BookSource?method=chapter&channelkey=6916f4f59737e43d43faeecb759b5e34&bid=6109&cid=1021506
  35. '''
  36. class banquanmao(object):
  37. name = name
  38. allowed_domains = allowed_domains
  39. source = source
  40. source_name = source_name
  41. source_id = source_id
  42. channelkey = 'ea1a4a2b760f1f385bc43b39abd0c6e0'
  43. def get_start_url(self):
  44. return base_url.format('booklist',self.channelkey)
  45. def bid_list_result(self, response):
  46. result = json.loads(response.text)
  47. if result is None or result.get('data') is None:
  48. return []
  49. result_list = []
  50. for item in result['data']:
  51. result_list.append({'id': item['id']})
  52. return result_list
  53. def get_book_info_url(self, bid):
  54. return base_url.format('bookinfo',self.channelkey) + '&bid={}'.format(bid)
  55. def book_info_result(self, response):
  56. result = json.loads(response.text)
  57. result = result['data']
  58. return {
  59. 'bid': result['id'], 'name': result['booktitle'], 'author': result['author'],
  60. 'intro': result['Introduction'], 'cover': result['cover'], 'keyword': result['Labels'],
  61. 'status': result['state'],
  62. 'category': result['nclass'],'category_id':result['category_id'],
  63. 'channel': result['channelid']
  64. }
  65. def get_chapter_list_url(self, bid):
  66. return base_url.format('chapterlist',self.channelkey) + '&bid={}'.format(bid)
  67. def chapter_list_result(self, response):
  68. result = json.loads(response.text)
  69. if result is None or result.get('data') is None:
  70. return []
  71. result_list = []
  72. for chapter_item in result['data']:
  73. result_list.append({
  74. 'source_chapter_id': chapter_item['id'], 'name': chapter_item['Title'],
  75. 'sequence': chapter_item['Orders'], 'is_vip': 1 if chapter_item['isVip'] else 0,
  76. 'size': chapter_item['chargeLength'], 'recent_update_at': chapter_item['updateTime']
  77. })
  78. return result_list
  79. def get_chapter_content_url(self, bid, cid):
  80. return base_url.format('chapter',self.channelkey) + '&bid={}&cid={}'.format(bid, cid)
  81. def chapter_content_result(self, response):
  82. result = json.loads(response.text)
  83. if result is None:
  84. return {'content': ''}
  85. return {
  86. 'content': result['data']['content']
  87. }
  88. class banquanmaoSpider(banquanmao, baseSpider):
  89. name = 'banquanmao'
  90. custom_settings = {
  91. 'DOWNLOAD_DELAY': 0.1,
  92. 'SOURCE': source,
  93. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  94. }
  95. class banquanmaoupdateSpider(banquanmao, baseUpdateSpider):
  96. name = 'banquanmaoupdate'
  97. custom_settings = {
  98. 'DOWNLOAD_DELAY': 0.1,
  99. 'SOURCE': source,
  100. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  101. }
  102. class banquanmaofixSpider(banquanmao, fixChapterSpider):
  103. name = 'banquanmaofix'
  104. custom_settings = {
  105. 'DOWNLOAD_DELAY': 0.1,
  106. 'SOURCE': source,
  107. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  108. }
  109. class banquanmaoBookInfoSpider(banquanmao, baseUpdateBookStatusSpider):
  110. name = 'banquanmaobookstatusinfo'
  111. custom_settings = {
  112. 'DOWNLOAD_DELAY': 0.1,
  113. 'SOURCE': source,
  114. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  115. }
  116. #-------------------------------------------------------------------------------------------------
  117. class lailiangSpider(banquanmao, baseSpider):
  118. name = 'lailiang'
  119. source = 'zy_lailiang'
  120. source_name = 'zy_lailiang来量'
  121. source_id = 37
  122. channelkey = '6916f4f59737e43d43faeecb759b5e34'
  123. custom_settings = {
  124. 'DOWNLOAD_DELAY': 0.1,
  125. 'SOURCE': source,
  126. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  127. }
  128. class lailiangupdateSpider(banquanmao, baseUpdateSpider):
  129. name = 'lailiangupdate'
  130. source = 'zy_lailiang'
  131. source_name = 'zy_lailiang来量'
  132. source_id = 37
  133. channelkey = '6916f4f59737e43d43faeecb759b5e34'
  134. custom_settings = {
  135. 'DOWNLOAD_DELAY': 0.1,
  136. 'SOURCE': source,
  137. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  138. }
  139. class lailiangfixSpider(banquanmao, fixChapterSpider):
  140. name = 'lailiangfix'
  141. source = 'zy_lailiang'
  142. source_name = 'zy_lailiang来量'
  143. source_id = 37
  144. channelkey = '6916f4f59737e43d43faeecb759b5e34'
  145. custom_settings = {
  146. 'DOWNLOAD_DELAY': 0.1,
  147. 'SOURCE': source,
  148. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  149. }
  150. class lailiangBookInfoSpider(banquanmao, baseUpdateBookStatusSpider):
  151. name = 'lailiangbookstatusinfo'
  152. source = 'zy_lailiang'
  153. source_name = 'zy_lailiang来量'
  154. source_id = 37
  155. channelkey = '6916f4f59737e43d43faeecb759b5e34'
  156. custom_settings = {
  157. 'DOWNLOAD_DELAY': 0.1,
  158. 'SOURCE': source,
  159. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  160. }