Python
3
Вклад в тег
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup as bs
from fake_useragent import UserAgent as usr
import requests
import re
def get_video(url):
ua = usr(cache=True)
hdr = {
'accept': '*/*',
'user-agent': ua.chrome
}
try:
resp = requests.get(url=url, headers=hdr)
sp = bs(resp.text, 'lxml')
video = sp.find(re.compile('iframe'), id='cdn-player')
.find('div', id='qplayer').find('div', id='qplayer_vbox')
.find('div', id='qplayer_controls').find('div', id='qplayer_download_control')
.find('div', class_='qp_down_nav').find(re.compile('^a')).get('href');
req = requests.get(video, headers=hdr, stream=True)
with open('video.mp4', 'wb') as file:
for chunk in req.iter_content(8192):
file.write(chunk)
except Exception as ex:
return 'Upps... Check the URL please!'
def main():
get_video('https://kinogo.biz/28467-hobbit-nezhdannoe-puteshestvie-2012.html')
if __name__ == '__main__':
main()