欢迎光临 - 我的站长站,本站所有资源仅供学习与参考,禁止用于商业用途或从事违法行为!

python教程

好看短视频解析下载Python脚本

python教程 我的站长站 2021-09-16 共102人阅读

前言

好看视频是百度旗下的短视频平台,里面有海量好看的短视频,遇到我们喜欢的,要如何下载呢。下面直接给出python语言中地址的解析及各种不同格式视频的下载。

#encoding:utf-8
# 好看视频下载
 
import socket
from urllib.request import urlopen
import urllib
import re
import time
from pyquery import PyQuery as pq
import requests
from tqdm import tqdm # 打印进度条的库
import gzip
 
print('程序开始运行。。。')
requests.adapters.DEFAULT_RETRIES = 5
# connect to a URL
timeout = 30
socket.setdefaulttimeout(timeout)#这里对整个socket层设置超时时间。后续文件中如果再使用到socket,不必再设置
sleep_download_time = 3
time.sleep(sleep_download_time) #这里时间自己设定
 
# 输入好看视频地址
haokanurl = input('请输入要下载的好看视频的网页地址:')
# haokanurl = 'https://haokan.baidu.com/v?vid=7448757459481911514&tab=yinyue_new'#示例地址
 
#为了避免出现403提示,这里伪装浏览器
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
req = urllib.request.Request(url=haokanurl, headers=headers)
website = urlopen(req,timeout = 90)
print('好看视频下载地址解析中')
 
# read html code
html = website.read().decode('UTF-8')
#html = website.read().decode()
#当使用上面的直接decode()出错时可以使用下面的方法
# html = website.read()
# buff = BytesIO(html)
# f = gzip.GzipFile(fileobj=buff)
# html = f.read().decode('utf-8')
website.close()
 
# use re.findall to get all the links
 
# 取得视频名称(标题)
videotitle = re.findall('<h1 class="videoinfo-title">(.*?)</h1>',html)[0]
print(videotitle)
# 默认地址
links = re.findall('"playurl":"(.*)","clarityUrl"',html)#默认地址
downurl = links[0]
downurl = downurl.replace('','')
print('视频实际地址:')
print(downurl)
print('现在开始下载该视频,请稍等。。。')
res = requests.get(downurl, headers={'user-agent': 'chrome'})
total_size = round(int(res.headers["Content-Length"])/1024/1024)
print('解析完成,视频大小为:' + str(total_size) + 'MB。现在开始下载。')
with open(f'{videotitle}down.mp4', 'wb') as f:
     for chunk in tqdm(iterable=res.iter_content(1024*1024), total=total_size, unit='KB'):
         f.write(chunk)
     print('下载完成。')
 
sdlinks = re.findall('"key":"sd","rank":0,"title":"(.*?)","videoBps":',html)[0]#标清地址
sdlinks = re.findall('"url":"(.*)',sdlinks)
sdurl = sdlinks[0]
sdurl = sdurl.replace('','')
print('标清视频地址是:')
print(sdurl)
print('现在开始下载标清视频,请稍等。。。')
res = requests.get(sdurl, headers={'user-agent': 'chrome'})
total_size = round(int(res.headers["Content-Length"])/1024/1024)
print('解析完成,视频大小为:' + str(total_size) + 'MB。现在开始下载。')
with open(f'{videotitle}标清.mp4', 'wb') as f:
     for chunk in tqdm(iterable=res.iter_content(1024*1024), total=total_size, unit='KB'):
         f.write(chunk)
     print('下载完成。')
 
 
hdlinks = re.findall('"key":"hd","rank":1,"title":"(.*?)","videoBps":',html)[0]#高清地址
hdlinks = re.findall('"url":"(.*)',hdlinks)
hdurl = hdlinks[0]
hdurl = hdurl.replace('','')
print('高清视频地址是:')
print(hdurl)
print('现在开始下载高清视频,请稍等。。。')
res = requests.get(hdurl, headers={'user-agent': 'chrome'})
total_size = round(int(res.headers["Content-Length"])/1024/1024)
print('解析完成,视频大小为:' + str(total_size) + 'MB。现在开始下载。')
with open(f'{videotitle}高清.mp4', 'wb') as f:
     for chunk in tqdm(iterable=res.iter_content(1024*1024), total=total_size, unit='KB'):
         f.write(chunk)
     print('下载完成。')
 
 
sclinks = re.findall('"key":"sc","rank":2,"title":"(.*?)","videoBps":',html)[0]#超清地址
sclinks = re.findall('"url":"(.*)',sclinks)
scurl = sclinks[0]
scurl = scurl.replace('','')
print('超清视频地址是:')
print(scurl)
print('现在开始下载超清视频,请稍等。。。')
res = requests.get(scurl, headers={'user-agent': 'chrome'})
total_size = round(int(res.headers["Content-Length"])/1024/1024)
print('解析完成,视频大小为:' + str(total_size) + 'MB。现在开始下载。')
with open(f'{videotitle}超清.mp4', 'wb') as f:
     for chunk in tqdm(iterable=res.iter_content(1024*1024), total=total_size, unit='KB'):
         f.write(chunk)
     print('下载完成。')
 
 
p1080links = re.findall('"key":"1080p","rank":3,"title":"(.*?)","videoBps":',html)[0]#蓝光地址
p1080links = re.findall('"url":"(.*)',p1080links)
p1080url = p1080links[0]
p1080url = p1080url.replace('','')
print('蓝光视频地址是:')
print(p1080url)
print('现在开始下载蓝光视频,请稍等。。。')
res = requests.get(p1080url, headers={'user-agent': 'chrome'})
total_size = round(int(res.headers["Content-Length"])/1024/1024)
print('解析完成,视频大小为:' + str(total_size) + 'MB。现在开始下载。')
with open(f'{videotitle}蓝光.mp4', 'wb') as f:
     for chunk in tqdm(iterable=res.iter_content(1024*1024), total=total_size, unit='KB'):
         f.write(chunk)
     print('下载完成。')
 
print('所有格式视频下载完成,请检查是否正确。')


相关专题
解析
解析
2022-03-03 1433

解析是一种破解限制下载工具,我的站长站为你整理收集所有关于解析的资源,包含视频解析软件,音乐解析软件,在线解析网站,通通都是免费解析下载必备软件....

相关推荐
  • Python脚本
  • python解析
  • 监测腾讯云轻量服务器流量超标关机python脚本

    脚本介绍一款监测腾讯云轻量应用服务器流量包使用情况,并根据配置进行警告和关机的Python脚本。GitHub:https://github.com/XiaoXinYo/Tencent_Cloud_LightHouse_Server_Guardian脚本功能仅用于轻量级服务器1.自动检测流量包剩余,可设置使用比2.自动关...

    python教程 75 1年前
  • Python无需认证QQ扫码登录脚本

    无需认证QQ扫码登录脚本python脚本,盗用JD的QQ登录,也可以改成其他网址。无需自己注册腾讯开发者,无需自己有一套网址去申请应用Get_QQ返回QQ号,也可以获取到QQ头像、好友等其他信息,请勿用于非法行为import requestsimport timefrom PIL import Imagedef...

    python教程 291 2年前
  • 最新python织梦dedecms远程执行脚本

    织梦CMS是使用最多的CMS之 一,但是漏洞也非常多。分享一款python写的织梦远程文件包含漏洞。修复此漏洞方法,请见文章底部。织梦CMS漏洞代码#! /usr/bin/env python#coding=utf-8#Joseph(小续)import requestsimport sysimport redef main():try:url="...

    服务器配置 282 4年前
  • Python获取抖音关注列表封号账号脚本

    抖音关注人数到达上限5000个了,需要挑选出关注列表中被封号的账号取关,手动非常麻烦,可以用下面这段Python抖音脚本。需要手动去抖音创作者平台获取cookie,注意,只是封了头像的用户也会获取的,因为原理就是判断头像地址。import requestsimport jsonimport...

    python教程 244 2年前
  • Python百度贴吧一键自动签到脚本

    Python贴吧签到脚本介绍相较于本地版本,此脚本新添了延时功能以防签到过快,并将代码放置在main函数中以提供入口(不再显示执行错误)更新说明4.18 可设置验证码错误的最大尝试次数;server酱推送更加详细;补充了云函数收费的说明。4.30 历史版本5.16 随...

    python教程 114 2年前
  • Python抖音官方接口分享

    抓了两个抖音的接口,一个是官方新的解析接口,另一个是拼接测试出来一个未公开的查用户信息的接口,一起分享给大家。代码放到阿里云的函数计算,可以直接托管到公网(腾讯云的云函数还需要自己配置API网关)。代码import requestsimport reheaders = {&#39;Use...

    python教程 168 2年前
  • Python好看视频地址解析下载代码

    #encoding:utf-8# 好看视频下载 import socketfrom urllib.request import urlopenimport urllibimport reimport timefrom pyquery import PyQuery as pqimport requestsfrom tqdm import tqdm # 打印进度条的库import gzip print(&#39;程序开始运...

    python教程 101 2年前
  • 好看短视频解析下载Python脚本

    前言好看视频是百度旗下的短视频平台,里面有海量好看的短视频,遇到我们喜欢的,要如何下载呢。下面直接给出python语言中地址的解析及各种不同格式视频的下载。#encoding:utf-8# 好看视频下载 import socketfrom urllib.request import urlopenimport ur...

    python教程 102 2年前
  • Python抖音去水印视频解析下载

    import reimport timeimport requeststemp_data = { &#39;headers&#39;: { &#39;User-Agent&#39;: &#39;Mozilla/5.0 (Linux; Android 10; ONEPLUS A6000 Build/QKQ1.190716.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0...

    python教程 58 2年前
  • 超星云盘Python解析直链方法

    超星云盘特点1、超星云盘是全国最大的图书数字化加工中心之一,安全有保证。2、拥有100GB免费存储空间,上传下载也同样是不限速的。3、网页版单文件上传,最高只支持1GB,而客户端是不限大小的。4、文件直链分享,就是不需要经过分享页面,点击后就能直接下载的...

    python教程 227 2年前