I have a list of url to songs’ tiktok page url in the form of f’https://www.tiktok.com/music/-{songid}’. If I enter it in my browser, I’ll be redirected to a page with a longer url, which is what I want to get.
I was trying methods in other posts using requests and urllib.request, but neither works. What’s happening? How could I get the redirected url in this case? Thank you!
For example, if I enter https://www.tiktok.com/music/-7224086788926638082 it in my browser, I’ll be redirected to https://www.tiktok.com/music/UNFORGIVEN-feat-Nile-Rodgers-7224086788926638082, which is what I want to get. However, the following codes both return the original url, instead of the redirected one:
import requests
url = 'https://www.tiktok.com/music/-7224086788926638082'
r = requests.get(url, allow_redirects=True)
print(r.url)
import urllib.request
url = 'https://www.tiktok.com/music/-7224086788926638082'
r = urllib.request.urlopen(url)
print(r.geturl())
1