import requests
class SendMsg:
def __init__(self):
self.url='https://www.zhihu.com/api/v4/messages'
#要发送的信息
self.data={'content':'小管家你好',
'receiver_hash':'****',#这里是每个用户的哈希值ID
'type':'common'
}
self.cookie={****}
def postmsg(self):
'''主要用于发送私信的方法requests.request(method, url, **kwargs)
支持各种方法 400请求错误 401验证不通过
用data还是json提交,看请求头content_type是不是json
cookies中需要token,不能从原始头复制'''
html=requests.request('POST',self.url,json=self.data,headers=self.header,cookies=self.cookie)
print(html.status_code)
print(html.json())
for i in range(2):
sending=SendMsg()
sending.postmsg()
#附上一个知乎用户数据爬取
import requests
class GetMsg:
'''获取粉丝信息'''
def __init__(self):
self.cookie = {'*****'}
self.header={'User-Agent':'***',
}
def getMag(self):
for i in range(120,140,20):
url='https://www.zhihu.com/api/v4/topics/19552832/followers?include=data[*]' \
'.gender,answer_count,articles_count,follower_count,' \
'is_following,is_followed&limit=20&offset={}'.format(i)
html=requests.request('GET',url=url,cookies=self.cookie,headers=self.header)
print(html.status_code)
content=html.json()
for c in content['data']:
if c['gender']==1:
print('男')
else:
print('女')
print(c['name'], c['headline'])
a=GetMsg()
a.getMag()
python 跨知乎app发私信以及Python专栏30万用户信息爬取
猜你喜欢
转载自blog.csdn.net/weixin_42557907/article/details/81585295
今日推荐
周排行