Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does Python crawl a nice little video?

Shulou Source: shulou.com Published: 2022-06-01 21:38:07 10月05日 Update

This article mainly explains "Python how to climb a good-looking small video", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Python how to climb a good-looking small video" bar!

Preface

The text and pictures of this article come from the network, only for learning, communication and use, do not have any commercial use, if you have any questions, please contact us in time to deal with.

Free online viewing of Python crawler, data analysis, website development and other case tutorials

Https://space.bilibili.com/523606542 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)

Thank you for reading, the above is the content of "how Python crawls good-looking videos". After the study of this article, I believe you have a deeper understanding of how Python crawls good-looking videos, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Content good-looking learning websites videos data data analysis methods modules environment problems analysis development funny code preface variables business online viewing address Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MySQL OPPO Reno Linux vpn