| 8 | import base64 |
| 9 | |
| 10 | class Spider(Spider): # 元类 默认的元类 type |
| 11 | def getName(self): |
| 12 | return "哔哩" |
| 13 | def init(self,extend=""): |
| 14 | print("============{0}============".format(extend)) |
| 15 | pass |
| 16 | def isVideoFormat(self,url): |
| 17 | pass |
| 18 | def manualVideoCheck(self): |
| 19 | pass |
| 20 | def homeContent(self,filter): |
| 21 | result = {} |
| 22 | cateManual = { |
| 23 | "Zard": "Zard", |
| 24 | "玩具汽车": "玩具汽车", |
| 25 | "儿童": "儿童", |
| 26 | "幼儿": "幼儿", |
| 27 | "儿童玩具": "儿童玩具", |
| 28 | "昆虫": "昆虫", |
| 29 | "动物世界": "动物世界", |
| 30 | "纪录片": "纪录片", |
| 31 | "相声小品": "相声小品", |
| 32 | "搞笑": "搞笑", |
| 33 | "假窗-白噪音": "窗+白噪音", |
| 34 | "演唱会": "演唱会" |
| 35 | } |
| 36 | classes = [] |
| 37 | for k in cateManual: |
| 38 | classes.append({ |
| 39 | 'type_name':k, |
| 40 | 'type_id':cateManual[k] |
| 41 | }) |
| 42 | result['class'] = classes |
| 43 | if(filter): |
| 44 | result['filters'] = self.config['filter'] |
| 45 | return result |
| 46 | def homeVideoContent(self): |
| 47 | result = { |
| 48 | 'list':[] |
| 49 | } |
| 50 | return result |
| 51 | cookies = '' |
| 52 | def getCookie(self): |
| 53 | rsp = self.fetch("https://www.bilibili.com/") |
| 54 | self.cookies = rsp.cookies |
| 55 | return rsp.cookies |
| 56 | def categoryContent(self,tid,pg,filter,extend): |
| 57 | result = {} |
| 58 | url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&duration=4&page={1}'.format(tid,pg) |
| 59 | if len(self.cookies) <= 0: |
| 60 | self.getCookie() |
| 61 | rsp = self.fetch(url,cookies=self.cookies) |
| 62 | content = rsp.text |
| 63 | jo = json.loads(content) |
| 64 | if jo['code'] != 0: |
| 65 | rspRetry = self.fetch(url,cookies=self.getCookie()) |
| 66 | content = rspRetry.text |
| 67 | jo = json.loads(content) |
nothing calls this directly
no outgoing calls
no test coverage detected