def getUpper(mid, cfg, proxy={}): url = "%s?vmid=%s" % (bilibili.upInfoUrl, str(mid)) response = bilibili.getHTMLText(url) if response == None: return None status_code = response[0] if status_code != 200: return status_code # 获取基本信息 updict = bilibili.getDict(response[1]) #---------------------------------------------------------- url = bilibili.upInfoDetailUrl postData = { 'csrf': cfg.getAttr('csrf'), #'099defc050cb8ad2827ca8493d06ab91' 'mid': mid } # 获取用户详细信息 r = requests.post(bilibili.upInfoDetailUrl, data=postData, headers=bilibili.detail_headers, proxies=proxy) status_code = r.status_code # 获取失败 if status_code != 200: return status_code res = bilibili.getDict(r.text) # 这里对regtime进行特殊处理是因为实践中发现regtime似乎并不是每个用户都有 # 有些特别的用户获取不到regtime. 另外有些字段获取的到不过为空或者其他什么奇怪的东西就是啦.. regtime = 0 if 'regtime' in res['data']: regtime = res['data']['regtime'] try: return upper(updict['data']['mid'], updict['data']['follower'], res['data']['name'], res['data']['face'], regtime, res['data']['sex'], res['data']['level_info']['current_level'], res['data']['vip']['vipType'], res['data']['vip']['vipStatus']) except: return None
def getSubmitNumber(self): url = "%s?mid=%s&page=1&pagesize=1" % (bilibili.submitUrl, str( self.mid)) # print(url) try: return bilibili.getDict(bilibili.getHTMLText(url))['data']['count'] except bException.bError as e: raise e
def getSubRepliesNum(self): try: url = "%s?pn=1&type=%d&oid=%d&sort=1&ps=1&root=%d" % ( bilibili.subreplyUrl, 1, self.aid, self.rid) res = bilibili.getDict(bilibili.getHTMLText(url)) return res['data']['page']['count'] except bException.bError as e: raise e
def getReply(self, page=1, sort=1): try: url = "%s?pn=%d&type=%d&oid=%d&sort=%d" % (bilibili.replyUrl, page, 1, self.aid, sort) # print(url) res = bilibili.getDict(bilibili.getHTMLText(url)) return self.__getReplyHelper(res['data']['replies']) except bException.bError as e: raise e
def getReplyInfo(self): try: url = "%s?pn=%d&type=%d&oid=%d&sort=%d" % (bilibili.replyUrl, 1, 1, self.getOid(), 1) res = bilibili.getDict(bilibili.getHTMLText(url)) resDict = {} resDict['acount'] = res['data']['page']['acount'] resDict['count'] = res['data']['page']['count'] except bException.bError as e: raise e
def getSubmitEx(self): url = "%s?mid=%s&page=1&pagesize=%s" % ( bilibili.submitUrl, str(self.mid), str(self.getSubmitNumber())) # print(url) submitDict = "" resList = [] try: submitDict = bilibili.getDict(bilibili.getHTMLText(url)) # print(submitDict) vlist = submitDict['data']['vlist'] # 遍历每一个投稿 for item in vlist: aid = item['aid'] submitDetailDict = {} detail = {} try: # 取得每一个投稿的详细信息 url = "%s?aid=%s" % (bilibili.submitDetailUrl, str(aid)) submitDetailDict = bilibili.getDict( bilibili.getHTMLText(url)) detail = submitDetailDict['data'] except: return [] resList.append( submit.submitEx(item['typeid'], item['play'], item['title'], item['created'], item['video_review'], item['favorites'], aid, self.mid, detail['reply'], detail['coin'], detail['like'], detail['his_rank'])) except: return resList return resList
def getSubReplies(self, sort=1): try: url = "%s?pn=1&type=%d&oid=%d&sort=%d&ps=%d&root=%d" % ( bilibili.subreplyUrl, 1, self.aid, sort, self.getSubRepliesNum(), self.rid) res = bilibili.getDict(bilibili.getHTMLText(url)) repliesList = [] subRepliesDict = res['data']['replies'] for r in subRepliesDict: nr = reply(r['content']['message'], r['member']['mid'], r['member']['uname'], r['floor'], r['ctime'], r['like'], r['content']['plat'], r['oid'], r['rpid'], r['root'], self.upmid) repliesList.append(nr) return repliesList except bException.bError as e: raise e
def getSubmit(self): url = "%s?mid=%s&page=1&pagesize=%s" % ( bilibili.submitUrl, str(self.mid), str(self.getSubmitNumber())) # print(url) submitDict = "" resList = [] try: submitDict = bilibili.getDict(bilibili.getHTMLText(url)) # print(submitDict) vlist = submitDict['data']['vlist'] # 遍历每一个投稿 for item in vlist: resList.append( submit.submit(item['typeid'], item['play'], item['title'], item['created'], item['video_review'], item['favorites'], item['aid'], self.mid)) except bException.bError as e: raise e return resList