Python爬虫入门教程18:好看视频的爬取

前言💨

本文的文字及图片来源于网络,仅供学习、交流使用,不具备任何商业用途,若有问题请及时联系咱们以做处理。python

前文内容💨

Python爬虫入门教程01:豆瓣Top电影爬取json

Python爬虫入门教程02:小说爬取api

Python爬虫入门教程03:二手房数据爬取网络

Python爬虫入门教程04:招聘信息爬取多线程

Python爬虫入门教程05:B站视频弹幕的爬取ide

Python爬虫入门教程06:爬取数据后的词云图制做学习

Python爬虫入门教程07:腾讯视频弹幕爬取网站

Python爬虫入门教程08:爬取csdn文章保存成PDFui

Python爬虫入门教程09:多线程爬取表情包图片url

Python爬虫入门教程10:彼岸壁纸爬取

Python爬虫入门教程11:新版王者荣耀皮肤图片的爬取

Python爬虫入门教程12:英雄联盟皮肤图片的爬取

Python爬虫入门教程13:高质量电脑桌面壁纸爬取

Python爬虫入门教程14:有声书音频爬取

Python爬虫入门教程15:音乐网站数据的爬取

Python爬虫入门教程17:音乐歌曲的爬取

PS:若有须要 Python学习资料 以及 解答 的小伙伴能够加点击下方连接自行获取
python免费学习资料以及群交流解答点击便可加入

基本开发环境💨

  • Python 3.6
  • Pycharm

相关模块的使用💨

import os
import requests

安装Python并添加到环境变量,pip安装须要的相关模块便可。

1、💥肯定需求

在这里插入图片描述
爬取搞笑趣味栏目的视频内容。

2、💥网站数据分析

首先须要明确一点,好看视频网站加载方式是懒加载的方式,须要你下滑网页才会加载出新的内容
在这里插入图片描述
加载出来的内容里面有音频播放地址以及标题。

内容比较简单,看代码就行

import os
import requests

url = '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('正在保存:', title)

在这里插入图片描述
在这里插入图片描述

相关文章
相关标签/搜索