Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use python to crawl and download bilibili video

Shulou Source: shulou.com Published: 2022-06-02 01:16:24 09月12日 Update

How to use python to crawl and download bilibili video, for this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

Bilibili is popular because of the coexistence of interest and knowledge. As the saying "you watch in bilibili, I study in bilibili", bilibili still has some good quality learning videos. What should you do when you see your favorite video on bilibili and want to save it?

To get to the point, this tweet mainly introduces how to download the favorite videos from bilibili to help more partners who need to learn. the detailed steps are as follows: the web page analyzes the results of video download methods to show the addition of Wechat video numbers. once again ignited the field of short videos, today we crawled bilibili's daily largest number of small videos, other types of videos can refer to this method.

Video download method

The web page has been analyzed in the previous section, and now we can use the requests.get method to get the short video on bilibili.

Core code

Def get_json (url): headers = {'User-Agent':' Mozilla/5.0 (X11) Linux x86x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'} params= {'page_size': 10,' next_offset': str (num), 'tag':' Hot Today', 'platform':' pc'} try: html = requests.get (url, params=params, headers=headers) return html.json () except BaseException: print ('request error') pass def download (url) Path): start = time.time () # start time size = 0 headers = {'User-Agent':' Mozilla/5.0 (X11) Linux x86 / 64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'} response = requests.get (url,headers=headers,stream=True) chunk_size= 1024 content_size = int (response.headers ['content-length']) if response.status_code = 200: with open (path,'wb') as file: for data in response.iter_content (chunk_size=chunk_size): file.write (data) size + = len (data)

Achievement presentation

In the previous section, we have shown how to download videos with Python. Let's show the results below.

This is the answer to the question about how to use python to crawl and download bilibili video. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Tags: Videos methods more video downloads questions analysis learning help guys partners results results presentation knowledge web pages solutions easy popular easy reason code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft OPPO Reno vpn Shulou Technology Huawei