Python Web Scraping saving Tik Tok video from url

Viewed 6860

I am trying to save videos from this url:

Original:

https://api2.musical.ly/aweme/v1/play/?video_id=v09044a20000beeff4c108gs7sflfdug

Link changes to this:

http://v16.muscdn.com/3d238aa3e1c34000ce53792155cd0e15/5bcf3070/video/tos/maliva/tos-maliva-v-0068/e5a1ab74d0b54f97b3578924a428e58d/

The video is from TikTok. When you go to the url, it instantly redirects you to another url. The other url is the one I want in order to save the video. However, the url it directs you to does not have a "view html source" option. I can inspect the element and that shows it has a video tag, but I cannot find a way to save the url between the tag. I am using python and beautifulsoup. I tried to do this with selenium, but to no effect.

1 Answers

Edit:

The link that it redirects to changes all the time! as of 27/08/2019, the link below works...

If you get Access denied you should check the link once again...

I think you should use other libraries for saving videos...

For example (in Python 3+):

import urllib.request


vid_url = "http://v19.muscdn.com/21b98c731608b8aa296ec31468c26dd1/5d652a88/video/tos/maliva/tos-maliva-v-0068/e5a1ab74d0b54f97b3578924a428e58d/?rc=amdvdnY7NDdpaDMzNTczM0ApdSlINzU2NTM0MzM2MzM1MzQ1b2k5ZmU5Z2c1ZGY5ZmQzPGZAaUBoNnYpQGczdilAZjY1QHJjYzRkLWBjYl8tLV4xNnNzOmk0NTU1LjQtLi4uMTQ0NTYtOiM2MDAtXjQzXzMxMTFeMWEzYSNvIzphLW8jOmAtbyMwLl4%3D"

urllib.request.urlretrieve(vid_url, "your_video_name.mp4")

If you insist on using selenium you can add options like this:

options = webdriver.ChromeOptions()
options.add_experimental_option("prefs", {
   "download.default_directory": r"C:\Users\xxx\downloads\Test",
   "download.prompt_for_download": False,
   "download.directory_upgrade": True,
   "safebrowsing.enabled": True
})
driver = webdriver.Chrome(chrome_options=options)

Hope this helps you!

Related