[快手解析視頻真實連接(爬取快手視頻)]
1.複製快手視頻連接(以下)python
陪伴是最常情的告白,守護是最沉默的陪伴…… #汪星人 #寵物避障挑戰 https://v.kuaishou.com/5xXNiL 複製此連接,打開【快手App】直接觀看!web
虛擬連接是:https://v.kuaishou.com/5xXNiL微信
2.代碼解析真實連接(這裏就不介紹代碼,有問題能夠留言)cookie
# -*- coding: utf-8 -*-"""Created on Fri May 15 13:17:21 2020@author: 李運辰"""
import requestsrequests.packages.urllib3.disable_warnings()headers = { # "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36",}headers2 = { #"Host":"music.liuzhijin.cn", "Host": "live.kuaishou.com", "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36", "Cookie": "did=web_c0f3196ec94d4837b5f7850e3ebac3b9; didv=1589520098000; clientid=3; client_key=65890b29", }def geturl(url0): #url0="https://v.kuaishou.com/5loz4u" res0 = requests.get(url0,headers=headers,verify=False) """轉接第二段""" cookie = res0.cookies.get_dict() cookie = str(cookie).replace("{","").replace("}","").replace(" ","").replace("'","").replace(",",";") headers3 ={ "Host": "v.kuaishou.com", "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36", "Cookie":cookie.replace(":","=") } headers4 ={ "Host": "live.kuaishou.com", "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36", "Cookie":cookie.replace(":","=") } res1 = requests.get(url0,headers=headers3,allow_redirects=False) url2 = res1.headers['Location'] url_00 = url2.split("userId=")[1].split("&")[0] """第一部分url""" url_0=url2.split("?")[0].split("/")[-1] res2 = requests.get(url2,headers=headers3,allow_redirects=False).request.headers """第二部分url""" url_1 = res2['Cookie'].split(";")[-1].replace(":","=") """完整url""" url = "https://live.kuaishou.com/u/"+url_00+"/"+url_0+"?"+url_1 #print(url) response = requests.get(url,headers=headers4) text = response.text """視頻連接""" v_url =text.split('"playUrl":"')[1].split(".mp4")[0]+".mp4" v_url = v_url.replace("u002F","") #print(v_url) return v_url
st="陪伴是最常情的告白,守護是最沉默的陪伴…… #汪星人 #寵物避障挑戰 https://v.kuaishou.com/5xXNiL 複製此連接,打開【快手App】直接觀看!"st ="http"+(st.split("複製")[0].split("http")[1].replace(" ",""))u = geturl(st)print(u)
3.解析結果以下:app
感謝優秀的你關注我~
正在學習爬蟲的你,能夠在「學習資料」專欄獲取學習資料
若是須要哪些python有關的學習資料,歡迎留言~學習
本文分享自微信公衆號 - Python爬蟲數據分析挖掘(zyzx3344)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。url