zl程序教程

您现在的位置是:首页 >  其他

当前栏目

最新视频连接解析地址

2023-02-19 12:19:55 时间

这里用一个开篇进行处理:

如果HTML一直返回JavaScript怎么办?

在网上都是各种使用谷歌的模拟器进行处理,但都不是我想要的。

所以我就找啊找找啊找,然后就找到了。

下面是我在2个小时内找到的方法,挨个测试出来的。

不容易,是否应该关注三连一下呢?

但是前面需要用一些词语盖过去。

先说一下打包的参数吧:

pyinstaller常用参数

-F 只在dist中产生一个exe文件。 -w 只对windows有效,不使用控制台。 -D 默认选项,除了exe外,还会在在dist中生成很多依赖文件,推荐使用。 -i设置好看的ico格式的图标,加上该参数,指定图标路径。 -p 设置导入路径

打包:

pyinstaller -F -w -p C:\Users\qwe84\AppData\Local\Programs\Python\Python39\Lib -i D:\save\study\python\pythonProject\python.ico GetDownRain.py -n "视频下载器"

测试用的: 

import requests
import re

import os

oldUrl = "URL"
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
}
short_url = re.findall('(http[|s]?://[^\s]*/)', oldUrl)[0]
url = requests.get(url=short_url, headers=headers).url
item_id = url.split('/')[5][0:19]
url = "https://www.iesdouyin.com/aweme/v1/web/aweme/detail/?aweme_id={0}".format(item_id)
html = requests.get(url, headers=headers)
title = html.json()['aweme_detail']['desc']

video_url = html.json()['aweme_detail']['video']['bit_rate'][0]['play_addr']['url_list'][0]
mp4 = requests.get(video_url, headers=headers).content

saveUrl = r"{0}.mp4".format(title)
file = open(saveUrl, "wb+")
file.write(mp4)
file.close()

打包用的:

import requests
import re

import os
from tkinter import *

import tkinter.messagebox as messagebox

root = Tk()

screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
dialog_width = 800
dialog_height = 100
# 前两个参数是窗口的大小,后面两个参数是窗口的位置
root.geometry(
    "%dx%d+%d+%d" % (dialog_width, dialog_height, (screenwidth - dialog_width) / 2, (screenheight - dialog_height) / 2))

root.title("(红目香薰提供):")
Label(root, text='url:').grid(row=0, column=0)
e = Entry(root, width=90)
e.grid(row=0, column=3, padx=10, pady=5)

root.resizable(height=False, width=False)

def show():
    try:
        oldUrl = e.get()
        headers = {
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
        }
        short_url = re.findall('(http[|s]?://[^\s]*/)', oldUrl)[0]
        url = requests.get(url=short_url, headers=headers).url
        item_id = url.split('/')[5][0:19]
        url = "https://www.iesdouyin.com/aweme/v1/web/aweme/detail/?aweme_id={0}".format(item_id)
        html = requests.get(url, headers=headers)
        title = html.json()['aweme_detail']['desc']

        video_url = html.json()['aweme_detail']['video']['bit_rate'][0]['play_addr']['url_list'][0]
        mp4 = requests.get(video_url, headers=headers).content
        # 开始下载
        saveUrl = r"{0}.mp4".format(title)
        file = open(saveUrl, "wb+")
        file.write(mp4)
        file.close()
        os.system("explorer .")
        messagebox.showinfo("提示", "{0}下载完毕!".format(title))
    except:
        messagebox.showinfo("提示", "错误路径")


Button(root, text='下载视频', width=10, command=show) \
    .grid(row=3, column=0, sticky=W, padx=10, pady=5)

mainloop()