In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use python to sort bilibili favorites according to video release time related knowledge, the content is detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that after reading this article on how to use python to sort bilibili favorites according to video release time will have a harvest, let's take a look at it.
The role of the program
Because most of the videos we see are obtained through recommendations, and most of the recommended videos have just been released, most of the collected videos are basically in the order in which they are released. Then through the program to reorder the videos in the favorites according to the release time, then it is almost the same as the order in which we collect videos.
Mechanism.
Use bilibili's API to obtain the video number of the video in the favorites, use the request library in python to obtain the html of the corresponding web page of the video, and then use the regular expression to get the video release time. Bind the release time to the video number, sort the video release time from small to large, and once again use bilibili's API to collect videos to the designated favorites.
Problems that arise
When the av number of bilibili video is less than eight digits, it is arranged according to the video release order, but when it reaches nine digits, it is not arranged according to the release order, so the video release time can only be obtained by visiting the video home page.
Bilibili's API will have an error code if it is accessed with high frequency for a long time, so it will be sleep after each call to API.
The intermediate program may fail for a variety of reasons, so the function of storing the intermediate state is added in the middle, otherwise it will be very slow to re-climb every time it dies.
Usage
When you create a Sort class object, pass userAgent,cookie,fid,toFid,csrf into the constructor of the class, and then call the sortVideos () method in the class to complete the sorting.
Import requests, json, time, re, datetime, randomclass WriteLog (object): def _ _ getCurrentTime (self): return str (time.ctime (time.time () def writeFile (self, fileName, l): with open (self.__getCurrentTime () + fileName,'w') as f: for i in l: f.write (str (I) +') class Sort (WriteLog): def _ init__ (self, fid) ToFid, csrf, userAgent, cookie, MinSleepTime=5, MaxSleepTime=10): self.MinSleepTime = MinSleepTime self.MaxSleepTime = MaxSleepTime self.fid = str (fid) self.toFid = str (toFid) self.csrf = csrf self.DeadVideo = [] self.headers = {'User-Agent': userAgent,' cookie': cookie} def _ Sleep (self): sleepTime = random.randint (self.MinSleepTime Self.MaxSleepTime) time.sleep (sleepTime) def _ getAllVideoId (self): print ('Start get all video ID') fid = self.fid res = [] cnt = 0 for i in range (100): if I = 0: continue url =' https://api.bilibili.com/x/v3/fav/resource/list? Media_id=' + fid +'& pn=' + str (I) +'& ps=20&keyword=&order=mtime&type=0&tid=0&platform=web&jsonp=jsonp' html = requests.get (url=url) Headers=self.headers) te = json.loads (html.text) te = te ['data'] [' medias'] if te! = None: for j in te: res.append (j ['id']) print (' num:', cnt, 'videoID:' J ['id']) cnt = cnt + 1 self.__Sleep () else: break print (' Finish get all video ID, in total% d'% (len (res) return res def _ addVideoToFavorite (self Vid): fid = self.toFid csrf = self.csrf url = 'https://api.bilibili.com/x/v3/fav/resource/deal' data = {' rid': vid, 'type':' 2, 'add_media_ids': fid,' del_media_ids':', 'jsonp':' jsonp' 'csrf': csrf,' platform': 'web',} requests.post (url=url, data=data, headers=self.headers) print (' finish add video% s to folder% s'% (vid, fid)) def _ _ getVideoPostTime (self Vid): vid = str (vid) url = 'https://www.bilibili.com/video/av' + vid text = requests.get (url). Text' 'data-vue-meta= "true" itemprop= "uploadDate" content= "2021-04-07 23:29:21" >
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.