Requests库分享系列:
Requests库(一)
Requests库(二)
Requests库(三)如何获取接口传参参数
Requests库(四)如何传递不一样的参数
Requests库(五)接口返回状态码
Requests库(六)接口返回响应头和请求Cookies
Requests库(七)重定向和超时
Requests(八)代理和会话对象
Requests库(九)准备的请求和SSL 证书验证
Requests库(十)接口请求认证
Requests库(十一)实战请求钉钉群机器人
Requests库(十二)实战获取今日头条24小时热文
Requests库(十三)利用钉钉机器人打造一个钉钉群定时推送今日头条24小时热闻
懒人必备,获取关注的最新视频推送。
首先,我们去打开快手
https://video.kuaishou.com/myFollow点开关注,自己登陆
然后打开F12后,就关注请求,晴空下,发现,关注刷新,就一个请求。

那么我们去请求下。
然后我们去拼装我们的请求即可。拼装如下
import requests,json
url='https://video.kuaishou.com/graphql'
headers={
"content-type": "application/json",
"Cookie": "你的cookie",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
}
data={
"operationName": "likeDataQuery",
"query": "fragment feedContent on Feed { type author { id name headerUrl following headerUrls { url __typename } __typename } photo { id duration caption likeCount realLikeCount coverUrl photoUrl coverUrls { url __typename } timestamp expTag __typename } canAddComment __typename}fragment photoResult on PhotoResult { result llsid expTag serverExpTag pcursor feeds { ...feedContent __typename } __typename}query likeDataQuery($pcursor: String, $semKeyword: String, $semCrowd: String, $utmSource: String, $utmMedium: String, $page: String) { likeData(pcursor: $pcursor, semKeyword: $semKeyword, semCrowd: $semCrowd, utmSource: $utmSource, utmMedium: $utmMedium, page: $page) { ...photoResult __typename }}","variables": {
"page": "follow",
"pcursor": "3xpz7ghihu5v39y_0",
"semCrowd": "",
"semKeyword": "",
"utmMedium":"",
"utmSource": ""}
}
data=(requests.post(url,data=json.dumps(data),headers=headers).json())
relust=(data['data']['likeData']['feeds'])
conets=""
for i in relust:
conets+=("作者:"+i['author']['name']+"\n")
conets+=("名称:"+i['photo']['caption']+"\n")
conets+=("喜欢人数:"+i['photo']['likeCount']+"\n")
conets+=("播放地址:"+"https://video.kuaishou.com/short-video/"+i['photo']['id']+"\n")
print(conets)最后我们的结果展示

然后同样我给放到了我的钉钉群里。
改造后
def requestskuaishou():
url='https://video.kuaishou.com/graphql'
headers={
"content-type": "application/json",
"Cookie": "您的cookie",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
}
data={
"operationName": "likeDataQuery",
"query": "fragment feedContent on Feed { type author { id name headerUrl following headerUrls { url __typename } __typename } photo { id duration caption likeCount realLikeCount coverUrl photoUrl coverUrls { url __typename } timestamp expTag __typename } canAddComment __typename}fragment photoResult on PhotoResult { result llsid expTag serverExpTag pcursor feeds { ...feedContent __typename } __typename}query likeDataQuery($pcursor: String, $semKeyword: String, $semCrowd: String, $utmSource: String, $utmMedium: String, $page: String) { likeData(pcursor: $pcursor, semKeyword: $semKeyword, semCrowd: $semCrowd, utmSource: $utmSource, utmMedium: $utmMedium, page: $page) { ...photoResult __typename }}","variables": {
"page": "follow",
"pcursor": "3xpz7ghihu5v39y_0",
"semCrowd": "",
"semKeyword": "",
"utmMedium":"",
"utmSource": ""}
}
data=(requests.post(url,data=json.dumps(data),headers=headers).json())
relust=(data['data']['likeData']['feeds'])
conets=""
for i in relust:
conets+=("作者:"+i['author']['name']+"\n")
conets+=("名称:"+i['photo']['caption']+"\n")
conets+=("喜欢人数:"+i['photo']['likeCount']+"\n")
conets+=("播放地址:"+"https://video.kuaishou.com/short-video/"+i['photo']['id']+"\n")
return conets
def sendHotToDing():
cond=requestskuaishou()
dingding='https://oapi.dingtalk.com/robot/send?access_token=您的钉钉机器人token'
dataone={
"msgtype": "text",
"text": {
"content":cond
},
}
reponse=requests.post(dingding,json=dataone)
if reponse.status_code==200:
if str(reponse.json()['errcode'])=="0":
print("推送成功")
else:
print("推送失败")
if __name__=="__main__":
sendHotToDing()看下效果如何:


设想一下,脚本每天监控今日头条和快手的热闻和关注的视频,每天定时给我推送到钉钉群,而且我限量了,每天只需要打开钉钉看一会就可以,告别天天刷头条,刷快手。也可以,直接发送到我们的小邮箱里面,做为我们每日的待做。是不是每天收完邮件,然后看一会新闻,看一会快手,不沉迷了。
如果觉得这篇文章还不错,来个【分享、点赞、在看】三连吧,让更多的人也看到~