




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
第Python實現簡單自動評論自動點贊自動關注腳本目錄前言開發(fā)環(huán)境原理:代碼實現1.請求偽裝2.獲取搜索內容的方法3.獲取作品評論4.自動評論5.點贊操作6.關注操作7.獲取創(chuàng)作者信息8.獲取創(chuàng)作者視頻9.調用函數
前言
今天的這個腳本,是一個別人發(fā)的外包,交互界面的代碼就不在這里說了,但是可以分享下自動評論、自動點贊、自動關注、采集評論和視頻的數據是如何實現的
開發(fā)環(huán)境
python3.8運行代碼
pycharm2025.2輔助敲代碼
requests第三方模塊
原理:
模擬客戶端,向服務器發(fā)送請求
代碼實現
1.請求偽裝
def__init__(self):
self.headers={
'content-type':'application/json',
'Cookie':'kpf=PC_WEB;kpn=KUAISHOU_VISION;clientid=3;did=web_ea128125517a46bd491ae9ccb255e242;client_key=65890b29;didv=1646739254078;_bl_uid=pCldq3L00L61qCzj6fytnk2wmhz5;userId=270932146;kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABH2BHihXp4liEYWMBFv9aguyfs8BsbINQIWqgoDw0SimMkpXwM7PKpKdJcZbU12QOyeKFaG4unV5EUkkEswL0HnA8_A9z2ujLlKN__gRsxU2B5kIYgirTDPiVJ3uPN1sU9mqvog3auoNJxDdbKjVeFNK1wQ5HTM_yUvYvmWOx9iC8IKcvnmo9YnG_J9ske-t-wiCWMgSCA25HN6MRqCMxuhoSnIqSq99L0mk4jolsseGdcwiNIiC8rjheuewIA1Bk3LwkNIYikU2zobcuvgAiBbMnBuDixygFMAE;kuaishou.server.web_ph=55c7e6b2033ea94a3447ea98082642cd6f1a',
'Host':'',
'Origin':'',
'Referer':'/search/videosearchKey=%E9%BB%91%E4%B8%9D',
'User-Agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/101.0.4951.67Safari/537.36',
self.url='/graphql'
2.獲取搜索內容的方法
defget_search(self,keyword,pcursor):
:paramkeyword:關鍵詞
:parampcursor:頁碼
:return:搜索作品
json={
'operationName':"visionSearchPhoto",
'query':"fragmentphotoContentonPhotoEntity{\nid\nduration\ncaption\nlikeCount\nviewCount\nrealLikeCount\ncoverUrl\nphotoUrl\nphotoH265Url\nmanifest\nmanifestH265\nvideoResource\ncoverUrls{\nurl\n__typename\n}\ntimestamp\nanimatedCoverUrl\ndistance\nvideoRatio\nliked\nstereoType\nprofileUserTopPhoto\n__typename\n}\n\nfragmentfeedContentonFeed{\ntype\nauthor{\nid\nname\nheaderUrl\nfollowing\nheaderUrls{\nurl\n__typename\n}\n__typename\n}\nphoto{\n...photoContent\n__typename\n}\ncanAddComment\nllsid\nstatus\ncurrentPcursor\n__typename\n}\n\nqueryvisionSearchPhoto($keyword:String,$pcursor:String,$searchSessionId:String,$page:String,$webPageArea:String){\nvisionSearchPhoto(keyword:$keyword,pcursor:$pcursor,searchSessionId:$searchSessionId,page:$page,webPageArea:$webPageArea){\nresult\nllsid\nwebPageArea\nfeeds{\n...feedContent\n__typename\n}\nsearchSessionId\npcursor\naladdinBanner{\nimgUrl\nlink\n__typename\n}\n__typename\n}\n}\n",
'variables':{'keyword':keyword,'pcursor':pcursor,'page':"search"}
response=requests.post(url=self.url,json=json,headers=self.headers)
json_data=response.json()
print(json_data)
returnjson_data
3.獲取作品評論
defget_comments(self,photoId,pcursor):
:paramphotoId:作品id
:parampcursor:頁碼
:return:評論內容
json={
'operationName':"commentListQuery",
'query':"querycommentListQuery($photoId:String,$pcursor:String){visionCommentList(photoId:$photoId,pcursor:$pcursor){\ncommentCount\nrootComments{\ncommentId\nauthorId\nauthorName\ncontent\nheadurl\ntimestamp\nlikedCount\nrealLikedCount\nliked\nstatus\nsubCommentCount\nsubCommentsPcursor\nsubComments{\ncommentId\nauthorId\nauthorName\ncontent\nheadurl\ntimestamp\nlikedCount\nrealLikedCount\nliked\nstatus\nreplyToUserName\nreplyTo\n__typename\n}\n__typename\n}\n__typename\n}\n}\n",
'variables':{'photoId':photoId,'pcursor':pcursor}
response=requests.post(url=self.url,json=json,headers=self.headers)
json_data=response.json()
print(json_data)
returnjson_data
4.自動評論
defpost_comment(self,content,photoAuthorId,photoId):
:paramcontent:評論內容
:paramphotoAuthorId:該作品的作者id
:paramphotoId:作品id
:return:有沒有成功
json={
'operationName':"visionAddComment",
'query':"mutationvisionAddComment($photoId:String,$photoAuthorId:String,$content:String,$replyToCommentId:ID,$replyTo:ID,$expTag:String){(photoId:$photoId,photoAuthorId:$photoAuthorId,content:$content,replyToCommentId:$replyToCommentId,replyTo:$replyTo,expTag:$expTag){\nresult\ncommentId\ncontent\ntimestamp\nstatus\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)
returnjson_data
5.點贊操作
defis_like(self,photoId,photoAuthorId):
:paramphotoId:作品id
:paramphotoAuthorId:該作品的作者id
:return:有沒有成功
json={
'operationName':"visionVideoLike",
'query':"mutationvisionVideoLike($photoId:String,$photoAuthorId:String,$cancel:Int,$expTag:String){\nvisionVideoLike(photoId:$photoId,photoAuthorId:$photoAuthorId,cancel:$cancel,expTag:$expTag){\nresult\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)
returnjson_data
6.關注操作
defis_follow(self,touid):
:paramtouid:用戶id
:return:
json={
'operationName':"visionFollow",
'query':"mutationvisionFollow($touid:String,$ftype:Int,$followSource:Int,$expTag:String){\nvisionFollow(touid:$touid,ftype:$ftype,followSource:$followSource,expTag:$expTag){\nfollowStatus\nhostName\nerror_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)
returnjson_data
7.獲取創(chuàng)作者信息
defget_userInfo(self,userId):
:paramuserId:用戶ID
:return:用戶信息
json={
'operationName':"visionProfile",
'query':"queryvisionProfile($userId:String){\nvisionProfile(userId:$userId){\nhostName\nuserProfile{\nownerCount{\nfan\nphoto\nfollow\nphoto_public\n__typename\n}\nprofile{\ngender\nuser_name\nuser_id\nheadurl\nuser_text\nuser_profile_bg_url\n__typename\n}\nisFollowing\n__typename\n}\n__typename\n}\n}\n",
'variables':{'userId':userId}
response=requests.post(url=self.url,json=json,headers=self.headers)
json_data=response.json()
print(json_data)
returnjson_data
8.獲取創(chuàng)作者視頻
defget_video(self,userId,pcursor):
:paramuserId:用戶id
:parampcursor:頁碼
:return:作品
json={
'operationName':"visionProfilePhotoList",
'query':"fragmentphotoContentonPhotoEntity{\nduration\ncaption\nlikeCount\nviewCount\nrealLikeCount\ncoverUrl\nphotoUrl\nphotoH265Url\nmanifest\nmanifestH265\nvideoResource\ncoverUrls{\nurl\n__typename\n}\ntimestamp\nexpTag\nanimatedCoverUrl\ndistance\nvideoRatio\nliked\nstereoType\nprofileUserTopPhoto\n__typename\n}\n\nfragmentfeedContentonFeed{\ntype\nauthor{\nid\nname\nheaderUrl\nfollowing\nheaderUrls{\nurl\n__typename\n}\n__typename\n}\nphoto{\n...photoContent\n__typename\n}\ncanAddComment\nllsid\nstatus\ncurrentPcursor\n__typename\n}\n\nqueryvisionProfilePhotoList($pcursor:String,$userId:String,$page:String,$webPageArea:String){\nvisionProfilePhotoList(pcursor:$pcursor,userId:$userId,page:$page,webPageArea:$webPageArea){\n
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 唐山大學考試試題及答案
- 就業(yè)規(guī)劃考試題及答案
- 課程運營筆試題及答案
- 工程付款面試題及答案
- 百事可樂考試題及答案
- 學生學習習慣養(yǎng)成與自主學習能力
- 心理健康教育宣傳手冊編制發(fā)放普
- Brand KPIs for car insurance:American Family Insurance in the United States-英文培訓課件2025.5
- 實施藝術教育特色項目打造學校品
- 構建學生綜合素質評價改革方案促
- SAP S4HANA 用戶操作手冊-成本控制CO操作手冊-002-訂單成本核算
- 幼兒園2025-2026學年度第一學期園本培訓計劃
- 科技史10:改變世界的10大科技發(fā)明
- 《培訓講師技能提升》課件
- 兩位數加兩位數口算練習題4000道203
- 2024年廣東省中考化學真題含解析
- 瑞格音混合矩陣培訓
- (完整版)康復診療指南及規(guī)范
- 寄售管理制度
- 農村土地轉讓合同協(xié)議
- 人教版八下Unit10詞匯精講(完整版)
評論
0/150
提交評論