python 实现批量发送知乎私信

用Python实现发送知乎私信
登录后手动给某个用户发送一条私信,抓包查看分析数据;注意分析可变参数;

使用request发送请求,将不同的人receiver_hash保存到文件中,打开文件循环遍历读取 实现给不同人发送;

 

 1 #coding=utf-8
 2 
 3 import requests
 4 import time
 5 import random
 6 
 7 class SendData:
 8     def __init__(self):
 9         self.url = 'https://www.zhihu.com/api/v4/messages'
10         self.header = {'User-Agent': ' '} #抓包获取值
11         self.cookie = {'Cookie': ' '} #抓包获取值
12 
13     def Send(self,dat):
14         self.html = requests.post(self.url,json=dat,cookies=self.cookie,headers=self.header)
15         print(self.html.status_code)
16 
17 if __name__ == '__main__':
18     send = SendData() #实例化
19     with open(r'D:\1.txt') as f:  #将爬取的用户hash保存到文件,打开文件, 实现给多个人批量发送私信
20         for hash in f:
21             time.sleep(random.randint(15,30)) #随机等待15到30秒
22             hash = hash.strip('\n') #去掉换行
23             dat = {'type': "common", 'content': "666", 'receiver_hash': hash}
24             send.Send(dat)

 

posted @ 2018-01-26 22:45  feiyueNotes  阅读(975)  评论(0)    收藏  举报