In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you a video about how to let Python climb bilibili. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Preface
Bilibili is a well-known video on-screen comment website, with the most timely animation Xinfan, ACG atmosphere, the most creative Up master. The video data in the site is divided into video picture and audio data.
Today, I will take you to download and merge bilibili's video.
Environment introduction:
Python 3.6
Pycharm
Requests
Re
Json
Subprocess
Parsing web pages
Target web page analysis
Crawler code
Import tool
Import requestsimport re # regular expression import pprintimport jsonimport subprocess
Request header
Headers = {'user-agent':' Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'}
Request data
Def send_request (url): response = requests.get (url=url, headers=headers) return response
Parsing video data
Def get_video_data (html_data): "" analyze video data "" # extract video title title = re.findall ('(. *?)', html_data) [0] # print (title) # extract video corresponding json data json_data = re.findall ('window\. _ playinfo__= (. *?)' Html_data) [0] # print (json_data) # json_data string json_data = json.loads (json_data) pprint.pprint (json_data) # extract audio url address audio_url = json_data ['data'] [' dash'] ['audio'] [0] [' backupUrl'] [0] print ('resolved audio address:' Audio_url) # extract the url address of the video image video_url = json_data ['data'] [' dash'] ['video'] [0] [' backupUrl'] [0] print ('resolved video address:', video_url) video_data = [title, audio_url, video_url] return video_data
Save data
Def save_data (file_name, audio_url, video_url): # request data print ('requesting audio data') audio_data = send_request (audio_url). Content print ('requesting video data') video_data = send_request (video_url) .content with open (file_name + '.mp3') Mode='wb') as f: f.write (audio_data) print ('saving audio data') with open (file_name + '.mp4', mode='wb') as f: f.write (video_data) print ('saving video data')
Consolidation of data
Def merge_data (video_name): print ('start of video synthesis:', video_name) # ffmpeg-I video.mp4-I audio.wav-CMV V copy-CVV aac-strict experimental output.mp4 COMMAND = f'ffmpeg-I {video_name} .mp4-I {video_name} .mp3-CVG v copy-CRAV an aac-strict experimental output.mp4' subprocess.Popen (COMMAND, shell=True) print ('end of video synthesis:', video_name)
Effect picture
Merge video and audio
A tool is used here. FFmpeg is an open source computer program that can be used to record, convert, and stream digital audio and video.
Unzip it after download, but you need to set the environment variable.
1. My computer, right mouse button click properties
2. Select advanced settings for the system
4. Add an environment variable, copy the file path, and select New to add.
.
The above is the editor for you to share how to let Python crawl bilibili video, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.