How to put a YouTube video?

Hi.
This is my problem: I have having the link in the video download the video itself in the folder.
But I don't know of rasshirenie, I.e. do not know whether it will be in .avi, or .mp4, or some.
I tried to like this:
html = req.get("link to some site")
soup = BS(html.text, features="html.parser")
link = soup.find("video")
video = req.get(link["src"])
with open("aaa","wb") as file:
 file.write(bytes(video.text.encode("utf-8")))

But alas, this video does not open.
Any ideas?
April 18th 20 at 13:09
1 answer
April 18th 20 at 13:11
Solution
there

Chrome - debug -f12
see what is loaded after clicking on Play

and how is it protected from download - advanced settings and stuff
I have done so, the parser works via user-agent and when I get the text of the video element, it goes something like:
ftypisom isomiso2avc1mp41 Emoov lmvhd : @ =trak \tkhd : @ $edts elst : mdia mdhd < U -VideoHandler vide hdlr `minf vmhd $dinf dref stbl stsd url avc1 H H 2avcCd gd in{ <1 h{, pasp stts stss 
ctts

Here's how to record correctly in the file, that he then opened? - mozelle_Hintz commented on April 18th 20 at 13:14
The truth in the comment is not visible, but I think you understand what I mean. - mozelle_Hintz commented on April 18th 20 at 13:17
with open("aaa","wb") as file:
file.write(bytes(video.text.encode("utf-8")))

is there confusion

wb OK

encode and don't need the video transmitted in binary mode - jedediah78 commented on April 18th 20 at 13:20
I tried that already, that's the error
file.write(bytes(video.text))
TypeError: string argument without an encoding - mozelle_Hintz commented on April 18th 20 at 13:23
not text
there is raw

look do not get headers in the raw - jedediah78 commented on April 18th 20 at 13:26
@adrian, Thanks.
I already did what was needed, turned out to VIDOS like this:
urllib.request.urlretrieve(link["src"], "video.mp4")
- mozelle_Hintz commented on April 18th 20 at 13:29

Find more questions by tags ParsingPythonVideo