一、先看效果:
包括短视频 中视频 长视频等。
短视频(2到3分钟时间):
中视频(10分钟左右时间):
长视频(20分钟左右时间):
二、爬取规则:
2.1:短视频爬取:
爬取该网页视频:
方法一:F12键 找到 network 然后media,数据包中的url,复制粘贴看是否能打开该视频,如果能打开该视频说明是视频的url路径。(缺点:只能一次爬取一个短视频)
完成上述操作后,直接上代码:
import requests
url="https://v3-webc.douyinvod.com/a3e6d9cff231516c8bd1552e4d99cbd8/65d5a5a1/video/tos/cn/tos-cn-ve-15/ocyUEQLyyPA74HrVBCfhgczWA6AemhMEIUtQCq/?a=6383&ch=26&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C3&cv=1&br=442&bt=442&cs=0&ds=4&ft=XzJ6BU7RxxoubA.g6Pm12lop0BanGbbIxCkwF_tP.Q952Nz7T&mime_type=video_mp4&qs=0&rc=N2Y8aWc7ZDQ3Ozg3NjllNEBpMzpnZjU6ZmVucTMzNGkzM0AtNmFhMDI2XzQxX181MTMtYSNtLWlecjRfcF5gLS1kLS9zcw%3D%3D&btag=e00028000&dy_q=1708496578&feature_id=46a7bb47b4fd1280f3d3825bf2b29388&l=2024022114225746CC8B79A4B8880FA88C"
headers={
'referer': "https://www.douyin.com/user/MS4wLjABAAAA8SA3crc5zzNVGUzHpsXq-MPYy9VIeu5omTmBlQ8JbGkL4W3GCNf0vTCbk_cKesDh?vid=7337467624470646056",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Core/1.94.225.400 QQBrowser/12.2.5541.400",
"cookie":"ttwid=1%7Cu5pvD9TtO5vOzdcH_ttIBiqwcsqCpaNNMTTdar62wmI%7C1706794538%7C5042e1a460efca604f75256f3f1eb4a497fdac4d6079e0dd81fa0cece2844ea3; passport_csrf_token=6f6c7cb74a48bc4e98e9c9ced76cd96c; passport_csrf_token_default=6f6c7cb74a48bc4e98e9c9ced76cd96c; bd_ticket_guard_client_web_domain=2; s_v_web_id=verify_ls39fghv_8G5JZCNJ_wex2_4IHV_8hx5_XViXsnFsqUYE; live_use_vvc=%22false%22; d_ticket=e70511571a116188ed588d904e61ebbd3c421; passport_assist_user=CkEkjHCT872vJbFYXkQ01qFHNjfuCCYTWcD41Mfv_xCl0FZjrqS7krYoxEKRXyhQVXZtET81nxQ5PFvyL-q9DrkUYBpKCjyWaFl1ROY1jVRgeQinSc93dgZVpdRMbbN0iz0fjJjgEyn2Ef8GziDTX4CBKV2P9UBB6xdosxVd_L7LAFoQjJ3IDRiJr9ZUIAEiAQOOqu_y; n_mh=vbvvaVvMvyp233dHkLKqRbiwVf9B_YcyQfk3XtXJJHI; sso_uid_tt=8b348700c4dfddee809c81f58ec749f2; sso_uid_tt_ss=8b348700c4dfddee809c81f58ec749f2; toutiao_sso_user=4711ad2c8e9fbd147979cfa1e4db64f9; toutiao_sso_user_ss=4711ad2c8e9fbd147979cfa1e4db64f9; sid_ucp_sso_v1=1.0.0-KDE2ZjA4ZTNmODE1MDA4ZGQ4YTdkMjg4Yjk0MGNkZDQyOWZiZjVhZWYKHwjNvvCLx430BxD0ve6tBhjvMSAMMMu0nIYGOAZA9AcaAmxmIiA0NzExYWQyYzhlOWZiZDE0Nzk3OWNmYTFlNGRiNjRmOQ; ssid_ucp_sso_v1=1.0.0-KDE2ZjA4ZTNmODE1MDA4ZGQ4YTdkMjg4Yjk0MGNkZDQyOWZiZjVhZWYKHwjNvvCLx430BxD0ve6tBhjvMSAMMMu0nIYGOAZA9AcaAmxmIiA0NzExYWQyYzhlOWZiZDE0Nzk3OWNmYTFlNGRiNjRmOQ; passport_auth_status=80749d0aaef0d868219baf0bf3a09993%2C; passport_auth_status_ss=80749d0aaef0d868219baf0bf3a09993%2C; uid_tt=a2f0a88c6e069615a360b7ca1e99df02; uid_tt_ss=a2f0a88c6e069615a360b7ca1e99df02; sid_tt=4c2afb50995ab645e7d2fe0a8bbfc859; sessionid=4c2afb50995ab645e7d2fe0a8bbfc859; sessionid_ss=4c2afb50995ab645e7d2fe0a8bbfc859; _bd_ticket_crypt_doamin=2; _bd_ticket_crypt_cookie=e16d75034613c129230b8c8000031d67; __security_server_data_status=1; LOGIN_STATUS=1; store-region=cn-jx; store-region-src=uid; sid_guard=4c2afb50995ab645e7d2fe0a8bbfc859%7C1707139280%7C4839464%7CMon%2C+01-Apr-2024+13%3A39%3A04+GMT; sid_ucp_v1=1.0.0-KGY4NDRjMDEyOWU1MmMwMTc3YWZlZWYzYmI1ZGU5ZDM5OTU4N2JhNWMKGwjNvvCLx430BxDQwYOuBhjvMSAMOAZA9AdIBBoCbHEiIDRjMmFmYjUwOTk1YWI2NDVlN2QyZmUwYThiYmZjODU5; ssid_ucp_v1=1.0.0-KGY4NDRjMDEyOWU1MmMwMTc3YWZlZWYzYmI1ZGU5ZDM5OTU4N2JhNWMKGwjNvvCLx430BxDQwYOuBhjvMSAMOAZA9AdIBBoCbHEiIDRjMmFmYjUwOTk1YWI2NDVlN2QyZmUwYThiYmZjODU5; __live_version__=%221.1.1.8009%22; home_can_add_dy_2_desktop=%220%22; dy_swidth=1536; dy_sheight=864; publish_badge_show_info=%220%2C0%2C0%2C1708091376148%22; live_can_add_dy_2_desktop=%221%22; pwa2=%220%7C0%7C1%7C0%22; douyin.com; device_web_cpu_core=8; device_web_memory_size=8; architecture=amd64; csrf_session_id=1a559086f14dad2f63b071267bc86cfd; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Atrue%2C%22volume%22%3A0.406%7D; FOLLOW_NUMBER_YELLOW_POINT_INFO=%22MS4wLjABAAAA35ljx2IsTNqQmiqHI75rahhIuslxsVM6mHfETnVCP0atvZVtKQdPHR20LWXrH6B7%2F1708444800000%2F0%2F1708424923405%2F0%22; download_guide=%223%2F20240220%2F0%22; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1536%2C%5C%22screen_height%5C%22%3A864%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A8%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A50%7D%22; __ac_nonce=065d550ca004431aa8d2a; __ac_signature=_02B4Z6wo00f01CBzAGwAAIDAoHH6LmzHENAgUwTAAG3QlahPwU653KZbHG8kzHREll-Cwbwj2I4e8jAEC0reSPXO4-I9p5inlL65SP7faC16RPKw9FpSyTYdKkL6Sm1OYkRZeleTBJEUQap4de; FOLLOW_LIVE_POINT_INFO=%22MS4wLjABAAAA35ljx2IsTNqQmiqHI75rahhIuslxsVM6mHfETnVCP0atvZVtKQdPHR20LWXrH6B7%2F1708531200000%2F0%2F1708478943677%2F0%22; strategyABtestKey=%221708478944.002%22; passport_fe_beating_status=true; xg_device_score=7.658235294117647; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCSm12VTk2SkwwUytNMzVGbDUxZVM1MHptL1dUY2lDMzJVblhQNVlBbDlrQVBJckdTVjN2WWlqTVk2RjhsdlVsK0h2RUJWbEcvMTEwdnlyNm1wSDBBbkU9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D; stream_player_status_params=%22%7B%5C%22is_auto_play%5C%22%3A0%2C%5C%22is_full_screen%5C%22%3A0%2C%5C%22is_full_webscreen%5C%22%3A1%2C%5C%22is_mute%5C%22%3A1%2C%5C%22is_speed%5C%22%3A1%2C%5C%22is_visible%5C%22%3A0%7D%22; msToken=CgmQuw4d6ew17FXDZqyKA_WcgMh0i-jCzLt9GZDWXLcOOxBlH3vjrtHF8KhhskJQsj3plPygwDyGmCFBr3nZ3jCelhua9GNrmEXWwjhdb8a8TrtK; msToken=YtyxIWHk5FTcqpxoC8cDiMtG-jLj94DL4W0eozRDkKg36P6Hq5P83Y0XNdbSdcXHSKc_QJX9uIDmku7JfqER9DPBRjSVU4yXQ-EItl4RJyDtnHOO; odin_tt=d8818eb9c7521d1bfef0b43350f3f74cc24b8519246173ed8246a87bcbbf6923d84d818fe189ea1dfdd13ba7d5c7dbda; tt_scid=TIsoAt2bIUb6ayjC0SnZxy5isuub3rVvp-8R-Ui0wGWSCFLINxDfMsieGlCLzzUr8e5b; IsDouyinActive=true"
}
response=requests.get(url=url,headers=headers).content
with open("b.mp4",mode="wb") as f:
f.write(response)
方法二:如上述url路径不能打开视频,则:搜索视频名称,找到对应数据包,能看到一些数据。如对应,则查找正确。(可爬取多个视频)
查找正确后进行分析,找到对应视频和音频(有时视频中包含了音频)路径:
import requests
url="https://www.douyin.com/aweme/v1/web/aweme/post/?device_platform=webapp&aid=6383&channel=channel_pc_web&sec_user_id=MS4wLjABAAAA8SA3crc5zzNVGUzHpsXq-MPYy9VIeu5omTmBlQ8JbGkL4W3GCNf0vTCbk_cKesDh&max_cursor=0&locate_item_id=7337467624470646056&locate_query=false&show_live_replay_strategy=1&need_time_list=1&time_list_query=0&whale_cut_token=&cut_version=1&count=18&publish_video_strategy_type=2&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1536&screen_height=864&browser_language=zh-CN&browser_platform=Win32&browser_name=QQBrowser&browser_version=12.2.5541.400&browser_online=true&engine_name=Blink&engine_version=94.0.4606.71&os_name=Windows&os_version=10&cpu_core_num=8&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7330626644485637673&msToken=CgmQuw4d6ew17FXDZqyKA_WcgMh0i-jCzLt9GZDWXLcOOxBlH3vjrtHF8KhhskJQsj3plPygwDyGmCFBr3nZ3jCelhua9GNrmEXWwjhdb8a8TrtK&X-Bogus=DFSzswVYFEvANHgdto4Xql9WX7Jd"
headers={
'referer': "https://www.douyin.com/user/MS4wLjABAAAA8SA3crc5zzNVGUzHpsXq-MPYy9VIeu5omTmBlQ8JbGkL4W3GCNf0vTCbk_cKesDh?vid=7337467624470646056",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Core/1.94.225.400 QQBrowser/12.2.5541.400",
"cookie":"ttwid=1%7Cu5pvD9TtO5vOzdcH_ttIBiqwcsqCpaNNMTTdar62wmI%7C1706794538%7C5042e1a460efca604f75256f3f1eb4a497fdac4d6079e0dd81fa0cece2844ea3; passport_csrf_token=6f6c7cb74a48bc4e98e9c9ced76cd96c; passport_csrf_token_default=6f6c7cb74a48bc4e98e9c9ced76cd96c; bd_ticket_guard_client_web_domain=2; s_v_web_id=verify_ls39fghv_8G5JZCNJ_wex2_4IHV_8hx5_XViXsnFsqUYE; live_use_vvc=%22false%22; d_ticket=e70511571a116188ed588d904e61ebbd3c421; passport_assist_user=CkEkjHCT872vJbFYXkQ01qFHNjfuCCYTWcD41Mfv_xCl0FZjrqS7krYoxEKRXyhQVXZtET81nxQ5PFvyL-q9DrkUYBpKCjyWaFl1ROY1jVRgeQinSc93dgZVpdRMbbN0iz0fjJjgEyn2Ef8GziDTX4CBKV2P9UBB6xdosxVd_L7LAFoQjJ3IDRiJr9ZUIAEiAQOOqu_y; n_mh=vbvvaVvMvyp233dHkLKqRbiwVf9B_YcyQfk3XtXJJHI; sso_uid_tt=8b348700c4dfddee809c81f58ec749f2; sso_uid_tt_ss=8b348700c4dfddee809c81f58ec749f2; toutiao_sso_user=4711ad2c8e9fbd147979cfa1e4db64f9; toutiao_sso_user_ss=4711ad2c8e9fbd147979cfa1e4db64f9; sid_ucp_sso_v1=1.0.0-KDE2ZjA4ZTNmODE1MDA4ZGQ4YTdkMjg4Yjk0MGNkZDQyOWZiZjVhZWYKHwjNvvCLx430BxD0ve6tBhjvMSAMMMu0nIYGOAZA9AcaAmxmIiA0NzExYWQyYzhlOWZiZDE0Nzk3OWNmYTFlNGRiNjRmOQ; ssid_ucp_sso_v1=1.0.0-KDE2ZjA4ZTNmODE1MDA4ZGQ4YTdkMjg4Yjk0MGNkZDQyOWZiZjVhZWYKHwjNvvCLx430BxD0ve6tBhjvMSAMMMu0nIYGOAZA9AcaAmxmIiA0NzExYWQyYzhlOWZiZDE0Nzk3OWNmYTFlNGRiNjRmOQ; passport_auth_status=80749d0aaef0d868219baf0bf3a09993%2C; passport_auth_status_ss=80749d0aaef0d868219baf0bf3a09993%2C; uid_tt=a2f0a88c6e069615a360b7ca1e99df02; uid_tt_ss=a2f0a88c6e069615a360b7ca1e99df02; sid_tt=4c2afb50995ab645e7d2fe0a8bbfc859; sessionid=4c2afb50995ab645e7d2fe0a8bbfc859; sessionid_ss=4c2afb50995ab645e7d2fe0a8bbfc859; _bd_ticket_crypt_doamin=2; _bd_ticket_crypt_cookie=e16d75034613c129230b8c8000031d67; __security_server_data_status=1; LOGIN_STATUS=1; store-region=cn-jx; store-region-src=uid; sid_guard=4c2afb50995ab645e7d2fe0a8bbfc859%7C1707139280%7C4839464%7CMon%2C+01-Apr-2024+13%3A39%3A04+GMT; sid_ucp_v1=1.0.0-KGY4NDRjMDEyOWU1MmMwMTc3YWZlZWYzYmI1ZGU5ZDM5OTU4N2JhNWMKGwjNvvCLx430BxDQwYOuBhjvMSAMOAZA9AdIBBoCbHEiIDRjMmFmYjUwOTk1YWI2NDVlN2QyZmUwYThiYmZjODU5; ssid_ucp_v1=1.0.0-KGY4NDRjMDEyOWU1MmMwMTc3YWZlZWYzYmI1ZGU5ZDM5OTU4N2JhNWMKGwjNvvCLx430BxDQwYOuBhjvMSAMOAZA9AdIBBoCbHEiIDRjMmFmYjUwOTk1YWI2NDVlN2QyZmUwYThiYmZjODU5; __live_version__=%221.1.1.8009%22; home_can_add_dy_2_desktop=%220%22; dy_swidth=1536; dy_sheight=864; publish_badge_show_info=%220%2C0%2C0%2C1708091376148%22; live_can_add_dy_2_desktop=%221%22; pwa2=%220%7C0%7C1%7C0%22; douyin.com; device_web_cpu_core=8; device_web_memory_size=8; architecture=amd64; csrf_session_id=1a559086f14dad2f63b071267bc86cfd; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Atrue%2C%22volume%22%3A0.406%7D; FOLLOW_NUMBER_YELLOW_POINT_INFO=%22MS4wLjABAAAA35ljx2IsTNqQmiqHI75rahhIuslxsVM6mHfETnVCP0atvZVtKQdPHR20LWXrH6B7%2F1708444800000%2F0%2F1708424923405%2F0%22; download_guide=%223%2F20240220%2F0%22; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1536%2C%5C%22screen_height%5C%22%3A864%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A8%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A50%7D%22; __ac_nonce=065d550ca004431aa8d2a; __ac_signature=_02B4Z6wo00f01CBzAGwAAIDAoHH6LmzHENAgUwTAAG3QlahPwU653KZbHG8kzHREll-Cwbwj2I4e8jAEC0reSPXO4-I9p5inlL65SP7faC16RPKw9FpSyTYdKkL6Sm1OYkRZeleTBJEUQap4de; FOLLOW_LIVE_POINT_INFO=%22MS4wLjABAAAA35ljx2IsTNqQmiqHI75rahhIuslxsVM6mHfETnVCP0atvZVtKQdPHR20LWXrH6B7%2F1708531200000%2F0%2F1708478943677%2F0%22; strategyABtestKey=%221708478944.002%22; passport_fe_beating_status=true; xg_device_score=7.658235294117647; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCSm12VTk2SkwwUytNMzVGbDUxZVM1MHptL1dUY2lDMzJVblhQNVlBbDlrQVBJckdTVjN2WWlqTVk2RjhsdlVsK0h2RUJWbEcvMTEwdnlyNm1wSDBBbkU9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D; stream_player_status_params=%22%7B%5C%22is_auto_play%5C%22%3A0%2C%5C%22is_full_screen%5C%22%3A0%2C%5C%22is_full_webscreen%5C%22%3A1%2C%5C%22is_mute%5C%22%3A1%2C%5C%22is_speed%5C%22%3A1%2C%5C%22is_visible%5C%22%3A0%7D%22; msToken=CgmQuw4d6ew17FXDZqyKA_WcgMh0i-jCzLt9GZDWXLcOOxBlH3vjrtHF8KhhskJQsj3plPygwDyGmCFBr3nZ3jCelhua9GNrmEXWwjhdb8a8TrtK; msToken=YtyxIWHk5FTcqpxoC8cDiMtG-jLj94DL4W0eozRDkKg36P6Hq5P83Y0XNdbSdcXHSKc_QJX9uIDmku7JfqER9DPBRjSVU4yXQ-EItl4RJyDtnHOO; odin_tt=d8818eb9c7521d1bfef0b43350f3f74cc24b8519246173ed8246a87bcbbf6923d84d818fe189ea1dfdd13ba7d5c7dbda; tt_scid=TIsoAt2bIUb6ayjC0SnZxy5isuub3rVvp-8R-Ui0wGWSCFLINxDfMsieGlCLzzUr8e5b; IsDouyinActive=true"
}
response=requests.get(url=url,headers=headers)
json=response.json()
list=json["aweme_list"]
aa=1
for i in list:
url=i["video"]["play_addr"]["url_list"][2]
a=requests.get(url=url,headers=headers).content
with open(f"{aa}.mp4",mode="wb") as f:
f.write(a)
aa += 1
2.2:中视频爬取:
爬取页面视频:
进行分析查找数据:
2.2.1:
1、首先f12键打开,进行刷新页面,找到第一个数据包。
2、打开response页面,在里面进行查找(搜索关键字如1080p等等)
3、代码
import requests
import re
import json
url="https://www.bilibili.com/video/BV1k4411y7pB/?spm_id_from=333.337.search-card.all.click"
headers={
"referer": "https://search.bilibili.com/all?vt=03127805&keyword=python%E7%88%AC%E5%8F%96%E8%A7%86%E9%A2%91&from_source=webtop_search&spm_id_from=333.1007&search_source=5",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36"
}
response=requests.get(url=url,headers=headers)
response=response.text
data=re.findall("window.__playinfo__=(.*?)</script>",response)[0] #re的正则查找 (.*?)的意思为查找括号内的所有内容
json=json.loads(data) #将 字符型 转换为 字典型
video=json['data']['dash']['video'][0]['baseUrl']
video_data=requests.get(video,headers=headers).content
with open("1.mp4",mode="wb") as f:
f.write(video_data)
2.3:长视频爬取:
爬取页面视频:
须知:长视频大多数是m3u8文件,m3u8文件又被分割为多个ts文件(即流媒体,把完整视频内容分割成n个短视频文件)
复制上诉代码到文本中找到下面蓝体路径(即最后一个https)即为url路径:
import requests
import re
url="https://apd-vlive.apdcdn.tc.qq.com/defaultts.tc.qq.com/B_JxNyiJmktHRgresXhfyMeg5wcigdXco5yUKBU4BqZo5aGNaObyhq3fvHqK_afj0a/svp_50112/ztDLQR4e7VAyyt5BCOw1Nx0UjLr5DT5u2dPXuUBoHaUrn7SwWsYsvmhrf7U8vdHsg4a4R-YMglt9qlEQuGn6GqhepnjZvxk1NMGjf7QkitfMAtKeKYvIN29WgwVvHTRh_f19ehvqeYmaMgpDjFFWruw8m8N2SrBqP_MaHymePunbsTyVhYwKEQqPzANYx4M3cgpVu2Q4poZflpaQYbhzD6GacDzWaIzkH0ZSZVLInNMHY9-xERl61Q/gzc_1000102_0b535uab2aaaimajarwuazs4b3oddxqqagka.f321002.ts.m3u8?ver=4"
headers={
"referer": "https://v.qq.com/",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36"
}
m3u8_text=requests.get(url,headers=headers).text
m3u8_text=re.sub("#E.*","",m3u8_text)
sub_ts=url.split("gzc")[0] #以gzc为切割点 去前一部分
ts_list=m3u8_text.split()#以空字符切割
for ts in ts_list:
ts_url=sub_ts + ts
print(ts_url)
print()
ts_data=requests.get(ts_url,headers=headers).content
with open("2.mp4",mode="ab") as f:
f.write(ts_data)
三、注意事项:
1、请求头中可能不仅需要user-agent 而且可能需要 referer和cookie等
2、有的视频直接包含音频,如包含则不用再去找音频
3、vscode存放的MP4视频有时可能打不开,可在文件夹中打开该视频。