欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

抖音视频无水印下载

程序员文章站 2022-04-11 15:48:38
...

抖音视频无水印下载

selenium yyds!!!
顺便推荐份通过api下载的py
我是没找到这api在哪,f12都翻烂了,直接懒人selenium了=_=
https://github.com/downdawn/JSreverse/blob/master/%E6%8A%96%E9%9F%B3/dy/parse_video.py

import requests
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import re

url = input('下载链接:')
if not url.startswith('https://www.douyin.com/video/'):
    r = '.*?(https://v.douyin.com/.*?/).*?'
    url = re.findall(r, url)[0]
print(url)

a = Options()
a.add_experimental_option("excludeSwitches", ["enable-automation"])
a.add_argument("--disable-blink-features=AutomationControlled")
a.add_argument('--headless')
a.add_argument('window-size=1920x1080')  # 指定浏览器分辨率
with open('./stealth.min.js') as fp:
    js = fp.read()
bro = webdriver.Chrome(options=a)
# 加载规避js
bro.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument",   {"source": js})
bro.maximize_window()    

bro.get(url)
time.sleep(2)
# 动作获取标签
url_mp4 = bro.find_element_by_xpath('//*[@id="root"]/div/div[2]/div[1]/div[1]/div[1]/div[1]/div/div[1]/div[2]/video').get_attribute("src")
name = bro.find_element_by_xpath('//*[@id="root"]/div/div[2]/div[1]/div[1]/div[1]/div[2]/h1/span[2]').text

headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'
}
response = requests.get(url_mp4,headers = headers)
code = response.status_code
print('\n响应码:',code)
content = response.content
with open('%s.mp4'%name,'wb') as fp:
    fp.write(content)
if code == 200:
    print('下载成功')
    
bro.quit()