from playwright.async_api import async_playwright
async def run(playwright, id):
browser = await playwright.chromium.launch()
page = await browser.new_page()
getpic = 0
getvideo = 0
await page.route('**', lambda route, request: asyncio.create_task(handle_request(route, request, getpic, getvideo)))
try:
await page.goto('https://m.douyin.com/share/video/'+id)
except Exception:
pass
await browser.close()
async def handle_request(route, request, getpic, getvideo):
if getpic == 1 and getvideo == 1:
return
if str(request.url).__contains__('is_play_url=1'):
print(f'视频URL----------------------: {request.url}')
getvideo = 1
elif str(request.url).__contains__('pcweb_cover'):
getpic = 1
print(f'封面URL======================: {request.url}')
else:
print(f'其他URL======================: {request.url}')
if request.url.endswith('.png') or request.url.endswith('.jpg'):
pass
else:
await route.continue_()
# 运行
async def main(id):
async with async_playwright() as playwright:
await run(playwright, id)
import asyncio
asyncio.run(main('抖音id'))
【python】保存抖音视频
最新推荐文章于 2026-05-19 08:39:58 发布

3769

被折叠的 条评论
为什么被折叠?



