這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)使用Python怎么下載抖音視頻,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
難點(diǎn):下載一個(gè)視頻可能很簡(jiǎn)單,但下載多個(gè)就稍微有點(diǎn)復(fù)雜,需要抓取多個(gè)視頻對(duì)應(yīng)的 url,抖音這塊做了防爬措施,只允許手機(jī)上看到個(gè)人主頁的視頻列表,電腦端的網(wǎng)頁卻看不到,這就需要抓取手機(jī)的 https 包,這里借助 Burpsuite 進(jìn)行抓包。
這里用到了 Burpsuite ,因此我把自己常用的 Burpsuite 2.1.06 專業(yè)版放在了網(wǎng)盤里面,公眾號(hào)「Python七號(hào)」回復(fù)「burp」獲取,下載后運(yùn)行start_burp.bat或sh start_burp.sh即可一鍵啟動(dòng),無需購買許可,非常方便。
找一個(gè)抖音視頻鏈接,點(diǎn)擊分享,復(fù)制鏈接,在電腦上用打開,然后打開開發(fā)者工具,點(diǎn)擊 network 選項(xiàng)。
刷新,看接口,找到返回值里有播放地址的接口:
然后開始寫代碼,獲取這個(gè) urllist[0],并下載
def get(share_url) -> dict: """ share_url -> 抖音視頻分享url 返回格式 [{'url':'', 'title','format':'',},{}] """ data = [] headers = { 'accept': 'application/json', 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1' } api = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={item_id}" rep = requests.get(share_url, headers=headers, timeout=10) if rep.ok: # item_id item_id = re.findall(r'video/(\d+)', rep.url) if item_id: item_id = item_id[0] # video info rep = requests.get(api.format(item_id=item_id), headers=headers, timeout=10) if rep.ok and rep.json()["status_code"] == 0: info = rep.json()["item_list"][0] tmp = {} tmp["title"] = info["desc"] #去水印的視頻鏈接 play_url = info["video"]["play_addr"]["url_list"][0].replace('playwm', 'play') tmp["url"] = play_url tmp["format"] = 'mp4' def get(share_url) -> dict: """ share_url -> 抖音視頻分享url 返回格式 [{'url':'', 'title','format':'',},{}] """ data = [] headers = { 'accept': 'application/json', 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1' } api = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={item_id}" rep = requests.get(share_url, headers=headers, timeout=10) if rep.ok: # item_id item_id = re.findall(r'video/(\d+)', rep.url) if item_id: item_id = item_id[0] # video info rep = requests.get(api.format(item_id=item_id), headers=headers, timeout=10) if rep.ok and rep.json()["status_code"] == 0: info = rep.json()["item_list"][0] tmp = {} tmp["title"] = info["desc"] #去水印的視頻鏈接 play_url = info["video"]["play_addr"]["url_list"][0].replace('playwm', 'play') tmp["url"] = play_url tmp["format"] = 'mp4' data.append(tmp) return data if __name__ =='__main__': videos = get('https://www.iesdouyin.com/share/video/6920538027345415431/?region=&mid=6920538030852885262&u_code=48&titleType=title&did=0&iid=0') for video in videos: downloader.download(video['url'],video['title'],video['format'],'./download') data.append(tmp) return data if __name__ =='__main__': videos = get('https://www.iesdouyin.com/share/video/6920538027345415431/?region=&mid=6920538030852885262&u_code=48&titleType=title&did=0&iid=0') for video in videos: downloader.download(video['url'],video['title'],video['format'],'./download')
上述就是小編為大家分享的使用Python怎么下載抖音視頻了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享標(biāo)題:使用Python怎么下載抖音視頻-創(chuàng)新互聯(lián)
網(wǎng)站鏈接:http://jinyejixie.com/article32/depssc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、定制開發(fā)、網(wǎng)頁設(shè)計(jì)公司、服務(wù)器托管、企業(yè)建站、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容