可爬取指定视频,根据视频播放的url爬取。
步骤
脚本
import json
import sys
import requests
from you_get import common as you_get
import time
import traceback
def down(video_id):
list=[video_id]
video_url = "https://www.bilibili.com/video/{0}"
for o in list:
try:
v_url = video_url.format(o)
print(v_url)
sys.argv = ['you-get', '--debug', '-o', "D:/video", v_url]
you_get.main()
time.sleep(10)
except Exception as e:
traceback.print_exc()
return list
if __name__ == "__main__":
video_id = input("请输入视频id:")
list = down(video_id)
升级版
根据视频播放urls批量下载,url用英文逗号分割,如输入:
https://www.bilibili.com/video/BV1nY411a7T8?p=1&vd_source=5a0bdb26f67e959b0ff9c8e5954d0070,https://www.bilibili.com/video/BV1nY411a7T8?p=3&vd_source=5a0bdb26f67e959b0ff9c8e5954d0070,https://www.bilibili.com/video/BV1nY411a7T8?p=9&vd_source=5a0bdb26f67e959b0ff9c8e5954d0070,https://www.bilibili.com/video/BV1nY411a7T8?p=10&vd_source=5a0bdb26f67e959b0ff9c8e5954d0070
脚本
import json
import sys
import requests
from you_get import common as you_get
import time
import traceback
def down(urls):
list=urls.split(',')
for i in list:
try:
v_url = i
print(v_url)
sys.argv = ['you-get', '--debug', '-o', "D:/video", v_url]
you_get.main()
time.sleep(10)
except Exception as e:
traceback.print_exc()
return list
if __name__ == "__main__":
urls = input("请输入视频url集合,使用英文逗号分割:")
list = down(urls)