今天來點特別的~ 不僅把好看的視頻全部pa下來,咱們還要實現自動評論、點贊、關註三連~ 寶,你也可以順手給我個三連嗎?給你個摸摸大~ 抓包分析流程 我寫成了文檔,都在這個PDF裡面了,但是好像不能上傳,所以點一下大家自行下載吧! 點我獲取,提取密碼 qwer 開始代碼 獲取視頻的代碼 import ...
今天來點特別的~
不僅把好看的視頻全部pa下來,咱們還要實現自動評論、點贊、關註三連~
寶,你也可以順手給我個三連嗎?給你個摸摸大~
抓包分析流程
我寫成了文檔,都在這個PDF裡面了,但是好像不能上傳,所以點一下大家自行下載吧!
點我獲取,提取密碼 qwer
開始代碼
獲取視頻的代碼
import requests # 發送請求 第三方模塊(第三方應用 pip) import re # 偽裝 # 1. 選中要替換的代碼 # 2. ctrl + R # 3. 第一個框(.*?): (.*) # 4. 在第二個框裡面輸入 '$1': '$2', # 5. 點擊全部替換(* 點亮 * 號) # Python學習交流群 279199867 headers = { 'content-type': 'application/json', 'Cookie': 'kpf=PC_WEB; kpn=KUAISHOU_VISION; clientid=3; did=web_ea128125517a46bd491ae9ccb255e242; client_key=65890b29; didv=1646739254078; userId=270932146; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABctRgGaXi5efEBpnbdtJMp3nnnXqENRWBoFQABtOr1ZFUNAjEo5NTZ4F0leSypsSFE4_-FGTnBqKEYh8Wcrszm3FGF03559Z9bFQCX_8ew_kLKPWVB9ZRlWQgISoG4-XZXIOqiBgkQKsPbpYKiA3X4_0rMDbo9-c0nWXeOoThekj8W3u7_yfI4fUY3h5WgTEDYT0yrXkZmhWlFV_jpVxDrBoSzFZBnBL4suA5hQVn0dPKLsMxIiCo1i0bY9V6-OVEk7yMnH86RNliTZACHvLPjL9FTHHQOigFMAE; kuaishou.server.web_ph=09735672944cbf9e53431bf3e0514a0d058b', 'Host': 'www.***.com', 'Origin': 'https://www.***.com', # 防盜鏈 'Referer': 'https://www.kuaishou.com/profile/3xhv7zhkfr3rqag', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36', } url = 'https://www.***.com/graphql' def get_page(pcursor): # 指定要誰的視頻 data = { "operationName": "visionProfilePhotoList", "query": "query visionProfilePhotoList($pcursor: String, $userId: String, $page: String, $webPageArea: String) {\n visionProfilePhotoList(pcursor: $pcursor, userId: $userId, page: $page, webPageArea: $webPageArea) {\n result\n llsid\n webPageArea\n feeds {\n type\n author {\n id\n name\n following\n headerUrl\n headerUrls {\n cdn\n url\n __typename\n }\n __typename\n }\n tags {\n type\n name\n __typename\n }\n photo {\n id\n duration\n caption\n likeCount\n realLikeCount\n coverUrl\n coverUrls {\n cdn\n url\n __typename\n }\n photoUrls {\n cdn\n url\n __typename\n }\n photoUrl\n liked\n timestamp\n expTag\n animatedCoverUrl\n stereoType\n videoRatio\n profileUserTopPhoto\n __typename\n }\n canAddComment\n currentPcursor\n llsid\n status\n __typename\n }\n hostName\n pcursor\n __typename\n }\n}\n", "variables": {"userId": "3x2vsxyxbbwcjta", "pcursor": pcursor, "page": "profile"} } # 1. 發送請求 get post response = requests.post(url=url, headers=headers, json=data) # <Response [200]>: 請求成功 # 2. 獲取數據 .json() 返回字典類型數據 # .text: 拿到的就是 文本內容 python數據類型 字元串 > 字典類型 > 鍵值對(拼音)方式取值 json_data = response.json() # 3. 解析數據 # 新華字典 = {'A': '啊', 'B': '不', 'C': '從'} # 新華字典['B'] python數據容器 存儲數據 # 正則 feeds = json_data['data']['visionProfilePhotoList']['feeds'] pcursor = json_data['data']['visionProfilePhotoList']['pcursor'] for feed in feeds: photoUrl = feed['photo']['photoUrl'] caption = feed['photo']['caption'] # 正則替換 # 第一個參數裡面是需要替換的一些字元 # 第二個參數 是把這些字元替換為 空 # 第三個參數 是需要替換的變數 # \\ : \ # \/ : / caption = re.sub('[\\\/:*?"<>|\n]', '', caption) print(caption, photoUrl) # 4. 保存數據 如果你們拿到的鏈接 就是 視頻 或者 音頻 或者 圖片 # .content: 獲取視頻(音頻 / 圖片) 二進位數據 video_data = requests.get(photoUrl).content # 視頻名稱 # wb 以二進位覆蓋寫入 with open(f'video/{caption}.mp4', mode='wb') as f: f.write(video_data) # 遞歸: 2.出口 if pcursor == "no_more": # 退出? return # 遞歸: 1.自己調用自己 get_page(pcursor) get_page("")
自動評論
def post_comment(self, content, photoAuthorId, photoId): """ :param content: 評論內容 :param photoAuthorId: 該作品的作者id :param photoId: 作品id :return: 有沒有成功 """ json = { 'operationName': "visionAddComment", 'query': "mutation visionAddComment($photoId: String, $photoAuthorId: String, $content: String, $replyToCommentId: ID, $replyTo: ID, $expTag: String) { (photoId: $photoId, photoAuthorId: $photoAuthorId, content: $content, replyToCommentId: $replyToCommentId, replyTo: $replyTo, expTag: $expTag) {\n result\n commentId\n content\n timestamp\n status\n __typename\n }\n}\n", 'variables': { 'content': content, 'expTag': "1_a/2005158523885162817_xpcwebsearchxxnull0", 'photoAuthorId': photoAuthorId, 'photoId': photoId } } response = requests.post(url=self.url, json=json, headers=self.headers) json_data = response.json() print(json_data) return json_data
自動點贊
def is_like(self, photoId, photoAuthorId): """ :param photoId: 作品id :param photoAuthorId: 該作品的作者id :return: 有沒有成功 """ json = { 'operationName': "visionVideoLike", 'query': "mutation visionVideoLike($photoId: String, $photoAuthorId: String, $cancel: Int, $expTag: String) {\n visionVideoLike(photoId: $photoId, photoAuthorId: $photoAuthorId, cancel: $cancel, expTag: $expTag) {\n result\n __typename\n }\n}", 'variables': { 'cancel': 0, 'expTag': "1_a/2005158523885162817_xpcwebsearchxxnull0", 'photoAuthorId': photoAuthorId, 'photoId': photoId } } response = requests.post(url=self.url, json=json, headers=self.headers) json_data = response.json() print(json_data) return json_data
自動關註
def is_follow(self, touid): """ :param touid: 用戶id :return: """ json = { 'operationName': "visionFollow", 'query': "mutation visionFollow($touid: String, $ftype: Int, $followSource: Int, $expTag: String) {\n visionFollow(touid: $touid, ftype: $ftype, followSource: $followSource, expTag: $expTag) {\n followStatus\n hostName\n error_msg\n __typename\n }\n}\n", 'variables': { 'expTag': "1_a/2005158523885162817_xpcwebsearchxxnull0", 'followSource': 3, 'ftype': 1, 'touid': touid } } response = requests.post(url=self.url, json=json, headers=self.headers) json_data = response.json() print(json_data) return json_data
溜了溜了,今天就到這裡,兄弟們快去試試吧!