import requests
import json
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'
}
def get_html(url):
print("正在获取第{}页数据".format(page))
resp = requests.get(url,headers=headers)
if resp.status_code == 200:
html = json.loads(resp.text)
return html
else:
print("异常状态响应码:",resp.status_code)
def parser_html(html):
a = html['data']
for b in a:
mp4_url = b['playUrl']
mp4_name = b['title'] + '.mp4'
save(mp4_url,mp4_name)
def save(mp4_url,mp4_name):
resp_2 = requests.get(mp4_url,headers=headers)
path = r'C:\Users\DELL\Desktop\python_wd\shipin\酷6视频\{}'.format(mp4_name)
print("\t正在保存 {} >>>>>>>>".format(mp4_name))
with open(path,'wb')as f:
f.write(resp_2.content)
def main(page):
url = 'https://www.ku6.com/video/feed?pageNo={}&pageSize=40&subjectId=76'.format(page)
html = get_html(url)
parser_html(html)
if __name__ == '__main__':
for page in range(1,6):
main(page)