爬虫下载网页视频(video blob))
现在视频链接一般为m3u8,找到m3u8地址就可以下载了打开Chrome Developer工具然后点击“网络”标签。导航到包含视频的页面然后开始播放。将文件列表过滤为“ m3u8”。找到master.m3u8或index.m3u8并单击它。将文件保存到磁盘并在其中查看。如果文件包含一个m3u8主URL则复制该URL。使用ffmpeg 工具下载m3u8视频ffmpeg -i https://secure.brightcove.com/services/mobile/streaming/index/rendition.m3u8?assetId6138283938001securetruevideoId6138277786001 -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 6138277786001.mp4Python下载代码#!/usr/bin/env python3importrequests,urllibfrombs4importBeautifulSoupimportosimportsubprocess pwdos.path.split(os.path.realpath(__file__))[0]urlhttps://www.topgear.com/videosheaders{upgrade-insecure-requests:1,user-agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36,accept:text/html,application/xhtmlxml,application/xml;q0.9,image/webp,image/apng,*/*;q0.8,accept-encoding:gzip, deflate, br,accept-language:zh-CN,zh;q0.9,en;q0.8,cookie:has_js1; minVersion{\experiment\:1570672462,\minFlavor\:\new_vermi-1.13.7.11.js100\}; minUniq%7B%22minUID%22%3A%22bb80328a30-e8cdeb4d55-9a314411d2-aff4bb11a6-4aa23e3779%22%7D; minDaily%7B%22testMode%22%3Atrue%2C%22dailyUser%22%3Atrue%7D; __gadsIDb6eee23a8df86f72:T1588041695:SALNI_MYCQR1Bf2fq53bqISIZBy8kIgI9oA; minBuffer%7B%22minAnalytics%22%3A%22%7B%5C%22clicks%5C%22%3A%5B%5D%2C%5C%22clicksDelay%5C%22%3A%5B%5D%7D%22%2C%22_minEE1%22%3A%22%5B%5D%22%7D; minSession%7B%22minSID%22%3A%227f32fd50ab-88cc4cf6f3-68d284cdee-1faeb65c08-c5966d76ac%22%2C%22minSessionSent%22%3Atrue%2C%22hadImp%22%3Atrue%2C%22sessionUniqs%22%3A%22%7Btime%3A1588053248571%2Clist%3A%5B11206251nt0%5D%7D%22%7D; OptanonConsentlandingPathNotLandingPagedatestampTueApr28202013%3A55%3A33GMT%2B0800(%E4%B8%AD%E5%9B%BD%E6%A0%87%E5%87%86%E6%97%B6%E9%97%B4)version3.6.24AwaitingReconsentfalsegroups1%3A1%2C101%3A0%2C2%3A0%2C0_132429%3A0%2C3%3A0%2C4%3A0%2C0_132431%3A0%2C104%3A0%2C106%3A0%2C111%3A0%2C114%3A0%2C120%3A0%2C124%3A0%2C126%3A0%2C130%3A0%2C133%3A0%2C134%3A0%2C144%3A0%2C145%3A0%2C146%3A0%2C147%3A0%2C150%3A0%2C151%3A0%2C157%3A0%2C162%3A0%2C173%3A0%2C0_126679%3A0%2C0_137695%3A0%2C0_132361%3A0%2C0_132391%3A0; GED_PLAYLIST_ACTIVITYW3sidSI6Ijh5clQiLCJ0c2wiOjE1ODgwNTMzNDksIm52IjowLCJ1cHQiOjE1ODgwNTMzMzMsImx0IjoxNTg4MDUzMzM3fV0.,cache-control:no-cache}if__name____main__:responserequests.request(GET,url,headersheaders)soupBeautifulSoup(response.text,html.parser)videoIdsoup.find_all(video,class_video-js)[0][data-video-id]##获取视频Idtitlesoup.find_all(h1,class_video-player__title)[0].contents[0]##获取视频标题urlhttps://secure.brightcove.com/services/mobile/streaming/index/master.m3u8?videoId{}securetrue.format(videoId)##生成视频下载Urlfilename{}.mp4.format(title).replace( ,-)cmd_strffmpeg -i \url\ -acodec copy -vcodec copy -absf aac_adtstoasc pwd/filename##下载视频print(cmd_str)subprocess.call(cmd_str,shellTrue)Python基础教程在SublimeEditor中配置Python环境Python代码中添加注释Python中的变量的使用Python中的数据类型Python中的关键字Python字符串操作Python中的list操作Python中的Tuple操作Pythonmax和min–在列表或数组中查找最大值和最小值Python找到最大的N个前N个或最小的N个项目Python读写CSV文件Python中使用httplib2–HTTPGET和POST示例Python将tuple开箱为变量或参数Python开箱Tuple–太多值无法解压Pythonmultidict示例–将单个键映射到字典中的多个值PythonOrderedDict–有序字典Python字典交集–比较两个字典Python优先级队列示例python 中如何格式化日期30 分钟 Python 爬虫教程爬虫下载网页视频 (video blob.html)