python教程

Python好看视频地址解析下载代码

我的站长站 2021-12-11 人阅读
#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 1444

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

相关推荐
  • python爬虫
  • python解析
  • Python源码
  • 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教程 108 2年前
  • python美女写真图库爬虫

    import requestsfrom lxml import etreeimport csvfrom time import sleepimport osfrom concurrent.futures import ThreadPoolExecutor headers = { &#39;user-agent&#39;: &#39;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit...

    python教程 46 2年前
  • 笔趣阁小说网Python爬虫分享

    #[url=https://www.biquge.info/wanjiexiaoshuo/]https://www.biquge.info/wanjiexiaoshuo/[/url] 笔趣阁小说全本爬虫import timeimport requestsimport osimport randomfrom lxml import etreeimport webbrowserheader = { "User-Agent": "Mo...

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

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

    python教程 171 3年前
  • 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教程 108 2年前
  • 好看短视频解析下载Python脚本

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

    python教程 106 2年前
  • Json压缩和格式化工具,附Python源码
    Json压缩和格式化工具,附Python源码

    软件介绍一款Json压缩和格式化工具,可以在线Json压缩和格式化。基于Python库开发,附上Python源码,GUI没有美化,巨丑。软件截图Python源码import jsonimport tkinter as tkdef json_compress(json_str...

    开发软件 34 10个月前
  • python打飞机小游戏源码+成品打包

    python源码用的pygame库,自带的random和os。程序运行需要的图片,声音和字体下载链接: https://pan.baidu.com/s/1KItG2usXOM_xcxcdHIixaw 提取码: qmweimport pygameimport randomimport os FPS = 60WIDTH = 500HEIGHT = 600 BLACK = (0, 0, 0)WHITE =...

    python教程 40 10个月前
  • 原创力文库Python爬虫下载源码

    # !/usr/bin/python# -*- coding: UTF-8 -*-import reimport jsonimport osimport shutilimport sysimport timeimport requestsimport img2pdffrom PIL import Image from alive_progress import alive_barfrom requests.exceptions import SSLErro...

    python教程 54 1年前
最新更新