爬取视频网站视频并下载
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了爬取视频网站视频并下载相关的知识,希望对你有一定的参考价值。
import requests
import os
import json
import time
import re
from retrying import retry
"""
爬虫*six room
"""
def change_title(file):
"""替换非法字符"""
pattern = re.compile(r"[/\:*?"<>|]")
file_name = re.sub(pattern,"_",file)
return file_name
def mp4_download_json():
for pages in range(1,101):
print(" 33[31;1m==========正在抓取第{}页的数据========== 33[0m".format(str(pages)))
url = "https://v.6.cn/minivideo/getlist.php?act=recommend&page={}&pagesize=20".format(pages)
headers = {
‘user-agent‘: ‘Mozilla/5.0 (Linux; android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36‘
}
response = requests.get(url,headers=headers)
html = response.text
# print(html)
dict_data = json.loads(html)
data_list = dict_data[‘content‘][‘list‘]
# print(data_list)
for data in data_list:
time.sleep(1)
mp4_url = data[‘playurl‘]
response = requests.get(mp4_url,headers=headers)
file_name = data[‘title‘]
new_filename = change_title(file_name)
# print(file_name)
if not os.path.exists(new_filename):
os.mkdir(new_filename)
print(" 33[31;1m正在下载 33[0m %s"%(new_filename))
with open(new_filename +‘/‘+new_filename+‘.mp4‘,‘wb‘) as f:
f.write(response.content)
print(" 33[32;1m%s~~~下载完成。 33[m
"%(new_filename))
if __name__ == "__main__":
mp4_download_json()
以上是关于爬取视频网站视频并下载的主要内容,如果未能解决你的问题,请参考以下文章
❤️ 爬取某网站小姐姐视频,源码奉上,保姆级教程,赶紧收藏❤️