




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第Python實(shí)現(xiàn)簡(jiǎn)單自動(dòng)評(píng)論自動(dòng)點(diǎn)贊自動(dòng)關(guān)注腳本目錄前言開(kāi)發(fā)環(huán)境原理:代碼實(shí)現(xiàn)1.請(qǐng)求偽裝2.獲取搜索內(nèi)容的方法3.獲取作品評(píng)論4.自動(dòng)評(píng)論5.點(diǎn)贊操作6.關(guān)注操作7.獲取創(chuàng)作者信息8.獲取創(chuàng)作者視頻9.調(diào)用函數(shù)
前言
今天的這個(gè)腳本,是一個(gè)別人發(fā)的外包,交互界面的代碼就不在這里說(shuō)了,但是可以分享下自動(dòng)評(píng)論、自動(dòng)點(diǎn)贊、自動(dòng)關(guān)注、采集評(píng)論和視頻的數(shù)據(jù)是如何實(shí)現(xiàn)的
開(kāi)發(fā)環(huán)境
python3.8運(yùn)行代碼
pycharm2025.2輔助敲代碼
requests第三方模塊
原理:
模擬客戶端,向服務(wù)器發(fā)送請(qǐng)求
代碼實(shí)現(xiàn)
1.請(qǐng)求偽裝
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:頁(yè)碼
: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.獲取作品評(píng)論
defget_comments(self,photoId,pcursor):
:paramphotoId:作品id
:parampcursor:頁(yè)碼
:return:評(píng)論內(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.自動(dòng)評(píng)論
defpost_comment(self,content,photoAuthorId,photoId):
:paramcontent:評(píng)論內(nèi)容
:paramphotoAuthorId:該作品的作者id
:paramphotoId:作品id
:return:有沒(méi)有成功
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:有沒(méi)有成功
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:頁(yè)碼
: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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 服裝入股協(xié)議書(shū)
- IT技術(shù)支持與維護(hù)服務(wù)協(xié)議規(guī)本
- 個(gè)人圖書(shū)出版合同
- 專(zhuān)業(yè)軟件安裝與維護(hù)協(xié)議
- 軟件定制化開(kāi)發(fā)合同協(xié)議
- 轉(zhuǎn)讓棋牌茶室協(xié)議書(shū)范本
- 郵輪乘務(wù)員派遣合同協(xié)議
- 造紙配件采購(gòu)合同協(xié)議
- 路牙石訂購(gòu)合同協(xié)議
- 進(jìn)修賠款協(xié)議書(shū)模板
- 寵物藥品研究報(bào)告-中國(guó)寵物藥品市場(chǎng)深度全景調(diào)研及投資前景分析報(bào)告2024年
- 2023年國(guó)考公告及職位表
- 【課程思政教學(xué)案例】《傳熱學(xué)》課程
- 大學(xué)生職業(yè)生涯規(guī)劃與就業(yè)指導(dǎo)第2版(高職)全套教學(xué)課件
- 中國(guó)兒童阻塞性睡眠呼吸暫停診斷與治療指南護(hù)理課件
- 江西康萊特新森醫(yī)藥原料有限公司年產(chǎn)100 噸注射用薏苡仁油生產(chǎn)項(xiàng)目環(huán)境影響報(bào)告
- 醫(yī)學(xué)影像數(shù)據(jù)庫(kù)建設(shè)與應(yīng)用研究
- 30題紀(jì)檢監(jiān)察位崗位常見(jiàn)面試問(wèn)題含HR問(wèn)題考察點(diǎn)及參考回答
- 胎兒宮內(nèi)窘迫的護(hù)理查房課件
- 海南跨境電商行業(yè)前景分析報(bào)告
- 婦科科室全面質(zhì)量與安全管理手冊(cè)
評(píng)論
0/150
提交評(píng)論