I'm trying to get a link from a voice message VKontakte. When you go to it, another link appears that you need to get. What I tried to do:

opener = urllib.request.build_opener() request = urllib.request.Request('https://vk.com/doc67915235_476512804') u = opener.open(request) print(u.geturl()) 

As a result, the same link is returned again: https://vk.com/doc67915235_476512804 but you need to return: https://psv4.userapi.com/c852436//u67915235/audiomsg/d4/495669fb43.ogg

  • And what happens when you download vk.com/doc67915235_476512804 ? Link to .ogg? Or the file itself is on the page and you want to get to its links? - gil9red
  • @ gil9red when I open this link vk.com/doc67915235_476512804 in a normal browser, then goes to the link with .ogg How to get the link .ogg in python? The original link will always be different - ANDROSHA
  • You need to watch what comes, mb there is a js-code that makes a transition to another link, mb that link returns a redirect and in the response header indicates a link to the transition - gil9red
  • @ gil9red and how can you find out? Manually something does not work, because the transition happens instantly - ANDROSHA
  • See what came in u - on the page itself, on the headlines. Or open a developer’s tool (F12) in the browser and see what requests were made on the network - gil9red

1 answer 1

You need to use the docs.getById API method. There you need to submit docs = 67915235_476512804

Here is the documentation about the parameter: https://vk.com/dev/docs.getById And then how to make requests to the API: https://vk.com/dev/api_requests

  • Well, the messages.getById method ANDROSHA helped me