Home python How to get a link to audio VK

How to get a link to audio VK




I was engaged in parsing VK music in python. As a result, I received audio recordings, BUT received them in this format (these are EXAMPLES !!! ):

audio45984371_456239025, audio45984371_456239024

etc. The question is: how to get a link to an audio recording from which you can download it (more precisely, how to automate the process for any audio recording)?

There is one “ugly” option – send a message to yourself, then accept it, and the attachments parameter will contain a link. How to do it differently?

The link should look something like this:

https: //cs1-49v4.vkuseraudio .net / p7 / 63c188880efb43.mp3? extra = 91fZRKv6nMs95XYyUSHRHSe1Fo4g49qL2T_pZFAyHXJZ9aVQDpZPPbSpGqaIzoR7yFofspMrkv7tGR7WDOU03G666g2tt7ifvYsR6kwp5L0BD6a-MNDnrCNdgsBtOaM4w-fMn1XIyWUnFwmorJDYyFV4

If you’re interested, here’s the Mouzon parsing code:

import lxml.html
import requests
import re
from itertools import islice
from bs4 import BeautifulSoup
import bot_vk
login = 'login'
password = 'mypassword'
url = 'http://vk.com/'
vk = bot_vk.auth_vk (login = login, password = password)
headers = {
'User-Agent': 'Mozilla / 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit / 537.36 (KHTML, like Gecko)',
'Accept': 'text / html, application / xhtml + xml, application / xml; q = 0.9, * / *; q = 0.8',
'Accept-Language': 'ru-ru, ru; q = 0.8, en-us; q = 0.5, en; q = 0.3',
'Accept-Encoding': 'gzip, deflate',
'Connection': 'keep-alive',
'DNT': '1'
#authorizable to receive music
session = requests.session ()
data = session.get (url, headers = headers)
page = lxml.html.fromstring (data.content)
form = page.forms [0]
form.fields ['email'] = login
form.fields ['pass'] = password
response = session.post (form.action, data = form.form_values ​​())
while True:
  response = session.post ("https://vk.com/audios" + str (input ()))
  #print (response.text)
  #da = re.findall ('data-audio = "\ [(. +) \]', response.text)
  da = re.findall ('data-full-id = "(. +?)"', response.text)
  print (da)
  qiy = ""
  for i in da:
    qiy + = "audio" + str (i) + ","
  qiy.split (",")

Answer 1, authority 100%

I was able to pull the link in this format:

Track: PHARAOH – Out of the way

https://sgi1.beeline-kz.vkuseraudio.net/p13/a094def19932e8.mp3?extra=nLFinFtz4cKRlWhxbzu- 1s0PY055QRDgwuHXwYbOMOwN2wlGg17S8eWL4lRcJL7qCo_NqDwUtyaZcAxGpbjbyqTrpPzp49zLgdL6xvlxh6-FyY9WdvFeNXplkvxflBOOP12

Track: Tim Belorusskikh – Wet crosses

https://sgi1.beeline-kz.vkuseraudio.net/p13/2e077269f04169.mp3?extra=J3SO2gCCQUPp94iOFSMjQiwOf- lGYAMORErnNjqCucAQ_LgxLXCR8qgD-1Iv1SeaW9gMiOHBWoCB0ba97JeA6S7fyMT5-LHMZHD08cz0U6mRpSGE8WMYTmkM6VKpKwkbdj1-VGRw

The song is downloaded if you click “save audio as”.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions