抖音无水印下载

10/01 10:33
阅读数 33

抖音无水印下载

用到selenium+requests+bs4+tkinter

对于设置禁止下载的视频也适用

1.提取链接
2.google浏览器打开——selenium
3.找到有水印的视频网址,去除水印——bs4
4.伪装成手机浏览器下载视频——requests
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述





import tkinter as tk
import tkinter.messagebox
from tkinter.filedialog import askdirectory
from tkinter import *
from selenium import webdriver
from time import sleep
from bs4 import BeautifulSoup
import random
import requests

headers = {
   
   'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1 Edg/84.0.4147.105'}

def get_http():
    info = t1.get(1.0, 'end')

    if ' 复制' in info:
        url1 = info.split('ht')[1].split(' 复制')[0]
        url = 'ht' + url1
    else:
        url = info
    print('网址提取成功')
    t2.insert(END, '网址提取成功\n')
    return url

def google_chrome(url):
    driver = webdriver.Chrome()
    driver.get(url)
    sleep(3)
    page = driver.page_source   #打出网页码源
    print('网页码源提取成功')
    t2.insert(END, '网页码源提取成功\n')
    return page

def look_pages(page):
    soup = BeautifulSoup(page, 'lxml')
    url_video = soup.find_all(mediatype="video")[0]
    name = soup.find_all(class_="name nowrap")[0]
    id = soup.find_all(class_="uid nowrap")[0]


    #取出水印
    url_video3 = url_video.get('src').replace('/playwm/', '/play/')
    name3 = name.text
    id3 = str(id).split('抖音号:')[1].split('</')[0]
    print('名字+视频网址提取成功')
    t2.insert(END, '名字+视频网址提取成功\n')
    return (url_video3, name3)

def download(url_video3, name3):
    tt = str(random.randrange(1, 100))  # 加入随机数,以免下载重复
    video = requests.get(url_video3, headers=headers).content
    path = address.get()
    with open(path+'/'+f'{name3+tt}.mp4', 'wb') as f:
        f.write(video)
    print('下载成功')
    t2.insert(END, '下载成功\n')
    tkinter.messagebox.showinfo('', '下载完成')


if __name__ == '__main__':
    def run():
        url = get_http()
        page = google_chrome(url)
        (url_video3, name3) = look_pages(page)
        download(url_video3, name3)

    window = tk.Tk()
    window.title('抖音无水印下载')
    window.geometry('500x300')

    l1 = Label(window, text='抖音复制链接', height=1)
    l1.pack(padx=0, anchor=W)

    t1 = tk.Text(window, height=3)
    t1.pack()  # 输入口



    def selectPath():
        path1 = askdirectory()
        address.insert(0, path1)


    address = Entry(window)
    address.place(x=0, y=70)
    Button(window, text="存储路径", command=selectPath).place(x=145, y=70)




    b1 = tk.Button(window, text='确定', font=('Arial', 12), width=10, height=1, command=(run))
    b1.pack(padx=10, anchor=E)

    l2 = Label(window, text='下载详情', height=1)
    l2.pack(padx=0, anchor=W)

    t2 = tk.Text(window, height=20)  # 输出显示口
    t2.pack(padx=0, anchor=S)

    window.mainloop()

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部