python 破解抖音直播源代码

python环境 python3.6及以上
所需第三方库 selenium、BeautifulSoup

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import json
import lxml
import os
import urllib
from selenium.webdriver import ChromeOptions
from bs4 import BeautifulSoup
from selenium import webdriver
import time
from selenium.webdriver.chrome.service import Service
# 获取抖音直播封面图片、链接、标题、主播名
if (os.path.isfile("test.txt")):

# os.remove() function to remove the file
os.remove("test.txt")

# Printing the confirmation message of deletion
print("File Deleted successfully")
else:
print("File does not exist")

url = 'https://www.douyin.com/follow'

print('正在打开浏览器')
options = ChromeOptions()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9014")
browser = webdriver.Chrome(executable_path=r"C:\Google\Chrome\Application\chromedriver.exe",
chrome_options=options)
browser.get(url)


time.sleep(3)

html =browser.page_source
soup = BeautifulSoup(html, 'lxml') # 生成BeautifulSoup对象

#hrefs =soup.find_all("a", class_="Jt6LO5RK o3pEYU7M")
for each in soup.findAll("a", class_="Jt6LO5RK o3pEYU7M"): # get all elements with 'a' tag
href = each.get('href')
href2 = href.replace('https://live.douyin.com/', 'https://live.douyin.com/webcast/room/web/enter/?aid=6383&app_name=douyin_web&live_id=1&web_rid=')
print(each)
print(href2)

browser.get(href2)
# time.sleep(1)
pre = browser.page_source
soup = BeautifulSoup(pre, 'lxml') # 生成BeautifulSoup对象
first_p_text = soup.find('pre').text

#jsontxt = urllib.parse.unquote(first_p_text)
res = json.loads(first_p_text)
# print(res)
try:
rtmp = res['data']['data'][0]['stream_url']['flv_pull_url']['FULL_HD1']
print(rtmp)
except Exception as e:
print('Exception:', e)
try:
rtmp = res['data']['data'][0]['stream_url']['hls_pull_url']
except Exception as e:
print('Exception:', e)
rtmp = "0"
print(rtmp)

Data = str(rtmp) + '\n'
with open("test.txt", "a") as f:
f.write(Data)
# 用字典保存直播间信息
browser.close()
# print(item['href'])

抖音直播源破解效果预览

image.png