版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
第Python實現(xiàn)簡單自動評論自動點(diǎn)贊自動關(guān)注腳本目錄前言開發(fā)環(huán)境原理:代碼實現(xiàn)1.請求偽裝2.獲取搜索內(nèi)容的方法3.獲取作品評論4.自動評論5.點(diǎn)贊操作6.關(guān)注操作7.獲取創(chuàng)作者信息8.獲取創(chuàng)作者視頻9.調(diào)用函數(shù)
前言
今天的這個腳本,是一個別人發(fā)的外包,交互界面的代碼就不在這里說了,但是可以分享下自動評論、自動點(diǎn)贊、自動關(guān)注、采集評論和視頻的數(shù)據(jù)是如何實現(xiàn)的
開發(fā)環(huán)境
python3.8運(yùn)行代碼
pycharm2025.2輔助敲代碼
requests第三方模塊
原理:
模擬客戶端,向服務(wù)器發(fā)送請求
代碼實現(xiàn)
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.獲取搜索內(nèi)容的方法
defget_search(self,keyword,pcursor):
:paramkeyword:關(guān)鍵詞
: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:評論內(nèi)容
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:評論內(nèi)容
: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.點(diǎn)贊操作
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.關(guān)注操作
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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 充填回收工安全規(guī)程競賽考核試卷含答案
- 硅油及乳液生產(chǎn)工安全應(yīng)急強(qiáng)化考核試卷含答案
- 油脂及脂肪酸加氫操作工安全理論評優(yōu)考核試卷含答案
- 玻璃制品機(jī)械成型工班組考核強(qiáng)化考核試卷含答案
- 中藥灸熨劑工崗前安全知識競賽考核試卷含答案
- 薄膜電阻器制造工崗前技術(shù)規(guī)范考核試卷含答案
- 九年級開學(xué)第一課主題班會課件
- 安全文明施工保證措施
- 交通應(yīng)急預(yù)案制定與演練制度
- 吊車保險培訓(xùn)課件大全
- 化工工藝安全管理與操作手冊
- 規(guī)范外匯交易管理制度
- 2026年美麗中國全國國家版圖知識競賽考試題庫(含答案)
- 高考英語讀后續(xù)寫技巧總結(jié)
- 2025年下半年河南鄭州市住房保障和房地產(chǎn)管理局招聘22名派遣制工作人員重點(diǎn)基礎(chǔ)提升(共500題)附帶答案詳解
- 維修事故協(xié)議書
- 2025ESC+EAS血脂管理指南要點(diǎn)解讀課件
- 2025至2030外周靜脈血栓切除裝置行業(yè)調(diào)研及市場前景預(yù)測評估報告
- 矛盾糾紛排查化解課件
- 2026年人力資源共享服務(wù)中心建設(shè)方案
- JJG(交通) 141-2017 瀝青路面無核密度儀
評論
0/150
提交評論