Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

beautifulsoup - Download Videos using python from ttdownloader

Hey guys I need some help, I am trying to download videos from this sitehttps://ttdownloader.com/dl.php?v=YTo0OntzOjk6IndhdGVybWFyayI7YjowO3M6NzoidmlkZW9JZCI7czoxOToiNjkxMjEwNzYyNzY1MjY5NzM1MCI7czozOiJ1aWQiO3M6MzI6Ijk0MTdiOWE3NWU2MmE3MDQ1NjZhYzk0MzJjMThlY2VlIjtzOjQ6InRpbWUiO2k6MTYxMTQ5NzE1ODt9 using python.

this is code I have tried.

import requests

url ='''https://ttdownloader.com/dl.php?v=YTo0OntzOjk6IndhdGVybWFyayI7YjowO3M6NzoidmlkZW9JZCI7czoxOToiNjkxMjEwNzYyNzY1MjY5NzM1MCI7czozOiJ1aWQiO3M6MzI6Ijk0MTdiOWE3NWU2MmE3MDQ1NjZhYzk0MzJjMThlY2VlIjtzOjQ6InRpbWUiO2k6MTYxMTQ5NzE1ODt9'''
page = requests.get(url)
with open('output.mp4', 'wb') as file:
    file.write(page.content)

But it doesnt work as expected, when i check page.content all I see is b''

question from:https://stackoverflow.com/questions/65871852/download-videos-using-python-from-ttdownloader

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

? The link that you are using is NOT a html page.
? Therefore it doesn't return anything as html.

? Your link is a media link.
? Therefore you must stream it and download it. Something like this:

import requests

url = '/your/valid/ttdownloader/url'
with requests.get(url, stream=True) as r:
    with open('ouput.mp4', 'wb') as f:
        for chunk in r.iter_content(chunk_size=8192): 
            f.write(chunk)

NOTE:
The link that you posted in the question is now invalid.
Please try the above code with a newly generated link.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...