When I get a link to a document via api vk, it’s not a direct link to it, but some kind of left one (if this is an image), wget cannot download it, but if it is inserted into the browser, it is redirected to the document. How does wget download it?

example how i do

elif item['attachments'][0]['doc']['title'][-4:] == '.png': commands.getoutput('wget -O in.png ' + item['attachments'][0]['doc']['url']) 

indirect: https://vk.com/doc333762526_445867303?hash=dc8fb03b38014898f3&dl=FUYTGMBZHAYDSOJX:1496487173:e55d0227cc0cf560bd&api=1&no_preview=1

Direct: https://psv4.userapi.com/c812639/u333762526/docs/a1eef5324a4d/out.png?extra=QHyn0neMwwB4pY2tiq4yrNYLOUA5EkoVhvcBWdi1uR0dR_hu1JW7QxUUp2TrSVhoqCcf3Yi9blYAQ4sB_mbMWIHz5osucrfK7KJraSOTXaxK6w0YZRHPvNDSOw

  • Link example? What is there such a 'left', javascript or something? - AK
  • Added examples - Gleb
  • @Gleb On the second (direct) link 404. Apparently, because you need your account in VK. But, I can manually take a direct link from the indirect. - Save14
  • There is no language label in your question - there is no chance that someone will find your question in its current form. - AK

1 answer 1

Try to surround the address in quotes:

 commands.getoutput("wget -O in.png '" + item['attachments'][0]['doc']['url'] + "'") 

But you definitely want to call an external command? Instead of doing it with a library? Like this (for 3+):

 from urllib.request import urlretrieve urlretrieve ("https://vk.com/doc...", "in.png")