爬取某看视频网视频
爬虫代码
# -*- coding=utf-8 -*-
# @Time: 2020/5/27 16:05
# @Author:石头
# @File:goodvideo.py
# @Software:PyCharm
import requests
page=0
while page<2:
page+=1
base_url ='https://haokan.baidu.com/videoui/api/videorec?tab=gaoxiao&act=pcFeed&pd=pc&num=20&shuaxin_id=1590566164654'
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'cookie': 'BIDUPSID=6A5EED306D80384F936F082950A8F160; PSTM=1587718724; BAIDUID=6A5EED306D80384F2F11CB15B9F1331D:FG=1; H_PS_PSSID=31624_1458_31672_21105_31591_31271_31463_30823; delPer=0; PSINO=3; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; BDSFRCVID=4T0sJeCCxG3HkwRuz68hL7-DeDfB4Z1-g_EP3J; H_BDCLCKID_SF=tR333R7oKRu_HRjYbb__-P4DHUjHfRO2X5REVKbmtPOkeqOJ2Mt5y-PW0loEtjv3BnkLKn5g5q_MoCDzbpnp05tpexbH55uetnuO_M5; PC_TAB_LOG=haokan_website_page; Hm_lvt_4aadd610dfd2f5972f1efee2653a2bc5=1590566149; Hm_lpvt_4aadd610dfd2f5972f1efee2653a2bc5=1590566149; reptileData=%7B%22data%22%3A%221fc8a49f6fb32d4cb00143e0a8bc6e432d97ac901f8b92267551cf3fad050d72a1cd609969992de6512aec94b948bcb08b612ef1215c7bbe623dfbcebbe0653f5c882e93fedeaf62bc9bc4403d51df731b40bbdf3bbb3686ea0a3f0879d74e7ebce8d37b22dc8be7d219b1342d8c0a1600a18ec6472ffb1f430c4115526221a8%22%2C%22key_id%22%3A%2230%22%2C%22sign%22%3A%22ae6dec54%22%7D'
}
response = requests.get(url=base_url,headers=headers)
# print(response.json())
# pprint.pprint(response.json())
data = response.json()
data_list = data['data']['response']['videos']
for data1 in data_list:
video_url = data1['play_url']
video_title = data1['title']+'.mp4'
video_data = requests.get(url=video_url,headers=headers).content
print("正在下载第{}页的视频:{}".format(page,video_title))
with open('video\\'+video_title,mode='wb') as f:
f.write(video_data)
print("下载完成",'\n')
#运行结果获取视频
转载:https://blog.csdn.net/weixin_45766024/article/details/106841376
查看评论