抖音匿名 直播间采集
if name == "main": api = DouyinAPIDemo() # 示例使用(需替换为合法获取的video_id) result = api.get_public_data("1234567890") if result: print(json.dumps(result, indent=2, ensure_ascii=False)):1.遵守robots协议 2.控制请求频率 3
:1.遵守robots协议 2.控制请求频率 3.仅采集公开可用数据。
import requests import json import time
class DouyinAPIDemo: def init(self): self.session = requests.Session() self.headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'Accept': 'application/json' }
python
复制代码
def get_public_data(self, video_id):
"""获取公开视频信息(模拟)"""
url = f"https://www.douyin.com/aweme/v1/web/aweme/detail/"
params = {
'aweme_id': video_id,
'device_platform': 'webapp'
}
try:
response = self.session.get(
url,
headers=self.headers,
params=params,
timeout=10
)
if response.status_code == 200:
return response.json()
return None
except Exception as e:
print(f"请求出错: {str(e)}")
return None
if name == "main": api = DouyinAPIDemo() # 示例使用(需替换为合法获取的video_id) result = api.get_public_data("1234567890") if result: print(json.dumps(result, indent=2, ensure_ascii=False))
import requests import json import time
class DouyinAPIDemo: def init(self): self.session = requests.Session() self.headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'Accept': 'application/json' }
python
代码解读
复制代码
if name == "main": api = DouyinAPIDemo() # 示例使用(需替换为合法获取的video_id) result = api.get_public_data("1234567890") if result: print(json.dumps(result, indent=2, ensure_ascii=False))
import requests import json import time
class DouyinAPIDemo: def init(self): self.session = requests.Session() self.headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'Accept': 'application/json' }
python
代码解读
复制代码
if name == "main": api = DouyinAPIDemo() # 示例使用(需替换为合法获取的video_id) result = api.get_public_data("1234567890") if result: print(json.dumps(result, indent=2, ensure_ascii=False))
更多推荐
所有评论(0)