Python之爬虫-酷6视频
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re
import requests
response = requests.get('https://www.ku6.com/index')
data = response.text
res = re.findall('<a class="video-image-warp" target="_blank" href="(.*?)">', data)
for r in res:
if r.startswith('/video/detail'):
r = f'https://www.ku6.com{r}'
video_i_response = requests.get(r)
video_i_data = video_i_response.text
video_url = re.findall('"video/mp4", src: "(.*?)"', video_i_data)[0]
video_name = video_url[0].split('_')[-1] + '.mp4'
video_response = requests.get(video_url)
video_data = video_response.content
with open(video_name, 'wb') as f:
f.write(video_data)
print('爬取成功: ' + video_name)