Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import requests
- import lxml.html
- import base64
- import json
- import sys
- url = 'http://www.dumpert.nl/mediabase/6801277/9f7c6290/max_verdedigt_tegen_rosberg.html'
- # read web page
- r = requests.get(url)
- #print('Status code:', r.status_code)
- #print('OK:', r.ok)
- # convert html text to html object
- html = lxml.html.fromstring(r.text)
- # get data-files from html object
- data = html.xpath('//@data-files')[0]
- # decode base64
- data = base64.b64decode(data)
- # convert bytes to string (Python 3)
- data = data.decode('utf-8')
- # convert json string into python dictionary
- data = json.loads(data)
- #print(data.keys())
- # get video url from dictionary
- print('mobile:', data['mobile'])
- print(' table:', data['tablet'])
- print(' 720p:', data['720p'])
- print(' image:', data['still'])
- # download video file
- video_url = data['tablet']
- local_filename = video_url.split('/')[-1]
- r = requests.get(video_url, stream=True)
- with open(local_filename, 'wb') as f:
- for chunk in r.iter_content(chunk_size=4096):
- if chunk:
- f.write(chunk)
- # show something on screen
- print('.', end='')
- sys.stdout.flush() # send on screen without buffering
- print('\n Done.')
Add Comment
Please, Sign In to add comment