Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to crawl a short video on a platform by Python

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how Python crawls a short video on a certain platform, which is concise and easy to understand, and can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Basic development environment

Python 3.6

Pycharm

The use of related modules import osimport requests

Install Python and add it to the environment variable, and pip installs the relevant modules you need.

First, determine the demand

Crawl the video content of the funny section.

Second, website data analysis

First of all, we need to make it clear that the loading mode of a good-looking video website is lazy, and you need to slide down the page to load new content.

The loaded content contains the audio playback address and title.

The content is relatively simple, just look at the code.

Import osimport requestsurl = 'https://haokan.baidu.com/videoui/api/videorec?tab=gaoxiao&act=pcFeed&pd=pc&num=20&shuaxin_id=1612592171486'headers = {' user-agent': 'Mozilla/5.0 (Windows NT 10.0 WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'} response = requests.get (url=url, headers=headers) json_data = response.json () videos = json_data ['data'] [' response'] ['videos'] for index in videos: title = index [' title'] play_url = index ['play_url'] video_content = requests.get (url=play_url Headers=headers) .content path = 'video\\' if not os.path.exists (path): os.mkdir (path) with open (path + title + '.mp4', mode='wb') as f: f.write (video_content) print ('saving:', title)

The above content is how Python crawls short videos on a certain platform. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report