第一步:獲取視頻所在的網頁python
第二步:F12中找到視頻真正所在的連接app
第三步:獲取連接並轉換成二進制ide
第四部:保存this
import re import requests response = requests.get('https://vd4.bdstatic.com/mda-jcrx64vi5vct2d2u/sc/mda-jcrx64vi5vct2d2u.mp4?auth_key=1557734214-0-0-d6a29a90222c6caf233e8a2a34c2e37a&bcevod_channel=searchbox_feed&pd=bjh&abtest=all') video = response.content #把文件保存成二進制 with open(r'D:\圖片\綠色.mp4','wb') as fw: fw.write(video) #將文件內容寫入該文件 fw.flush() #刷新
#有點偷懶變量名用簡單字母啦............. # https://www.ku6.com/index # <a class="video-image-warp" target="_blank" href="(.*?)"> #this.src({type: "video/mp4", src: "(.*?)"}) #src({type: "video/mp4", src: "(.*?)"}) import re # 載入模塊 import requests # 載入模塊 new_list = [] time = 0 response = requests.get('https://www.ku6.com/index') data = response.text # print(data) url = re.findall('<a class="video-image-warp" target="_blank" href="(.*?)">',data) for a in url : #type:str if a.startswith('/v') or a.startswith('/d'): new_list.append(f'https://www.ku6.com{a}') elif a.startswith('ht'): new_list.append(f"{a.split('垃')[0]}") for url_1 in new_list: response_1 = requests.get(url_1) data_1 = response_1.text video = re.findall('<source src="(.*?)" type="video/mp4">',data_1) or re.findall('type: "video/mp4", src: "(.*?)"',data_1) video_1 = video[0] x = video_1.split('/')[-1] name = f'{x}.mp4' video_response = requests.get(video_1) video_3 = video_response.content with open(f'D:\圖片\{name}','wb') as fw: fw.write(video_3) fw.flush() time += 1 print(f'已經爬取{time}個視頻')