def sample_code(): client = ZhihuClient() cookie_file_name = 'cookie.json' people_main_page = 'http://www.zhihu.com/people/liu-shi-qi-5-21' if os.path.exists(cookie_file_name): client.login_with_cookies(cookie_file_name) else: client.create_cookies(cookie_file_name) me = client.author(people_main_page) print('id:', me.id) print('name:', me.name) print('motto:', me.motto) print('photo:', me.photo_url) print('followee number:', me.followee_num) print('follower number:', me.follower_num) for i in range(1000): print(me.motto) followees = [] followers = [] for man in me.followees: print(man.id, '/', man.name) followees.append(man.id) for man in me.followers: print(man.id, '/', man.name) followers.append(man.id) save = ZhihuUser(me.id, followees, followers) save.save('save.json')
#!/usr/bin/env python3 # -*- coding: utf-8 -* from zhihu import ZhihuClient #client = ZhihuClient() #client.set_proxy('http://ucbcn\cnt0095:[email protected]:8080') #client.login_in_terminal() #client.create_cookies('cookies.json') Cookies_File = 'cookies.json' client = ZhihuClient(Cookies_File) client.set_proxy('http://ucbcn\cnt0095:[email protected]:8080') url = 'http://www.zhihu.com/people/douzishushu' author = client.author(url) print('用户名 %s' % author.name) print('用户简介 %s' % author.motto) print('用户关注人数 %d' % author.followee_num) print('取用户粉丝数 %d' % author.follower_num) print('用户得到赞同数 %d' % author.upvote_num) print('用户得到感谢数 %d' % author.thank_num) print('用户提问数 %d' % author.question_num) print('用户答题数 %d' % author.answer_num) print('用户专栏文章数 %d,名称分别为:' % author.post_num) for column in author.columns: print(column.name) print('用户收藏夹数 %d,名称分别为:' % author.collection_num) for collection in author.collections: print(collection.name)
USER_URL = "https://www.zhihu.com/people/7sdream" FOLLOWER_CHECK_MAX_NUM = 2000 ANSWER_CHECK_MAX_NUM = 20 # ============================== def is_zero_user(author): return (author.upvote_num + author.question_num + author.answer_num) <= 3 client = ZhihuClient('test.json') user = client.author(USER_URL) print("检查用户{user.name} at {time}".format(user=user, time=datetime.datetime.now())) if user.follower_num < FOLLOWER_CHECK_MAX_NUM: FOLLOWER_CHECK_MAX_NUM = user.follower_num print("正在检查前{FOLLOWER_CHECK_MAX_NUM}个关注者....".format(**locals())) zeros = 0 for _, follower in zip(range(FOLLOWER_CHECK_MAX_NUM), user.followers): if is_zero_user(follower): zeros += 1 rate = zeros / FOLLOWER_CHECK_MAX_NUM
from zhihu import ZhihuClient Cookies_File = 'cookies.json' client = ZhihuClient(Cookies_File) dict={} author = client.author('https://www.zhihu.com/people/zhang-jia-wei') #author = client.author('https://www.zhihu.com/people/mo-ming-42-91') print('--- Followers ---') for follower in author.followers: if(follower.education!='unknown'): print(follower.name,follower.education) with open('zhihu.txt','a') as f: f.write(follower.name+": "+follower.education+"\n") if(follower.education in dict): dict[follower.education]+=1 else: dict[follower.education]=1 '''print('--- Followees ---') for followee in author.followees: print(followee.name,followee.education)''' print(dict) with open('zhihu.txt','a') as f: f.write(str(dict)+"\n")
from zhihu import ZhihuClient Cookies_File = 'cookies.json' client = ZhihuClient(Cookies_File) url = 'http://www.zhihu.com/people/excited-vczh' author = client.author(url) print('用户名 %s' % author.name) print('用户简介 %s' % author.motto) print('用户关注人数 %d' % author.followee_num) print('取用户粉丝数 %d' % author.follower_num) print('用户得到赞同数 %d' % author.upvote_num) print('用户得到感谢数 %d' % author.thank_num) print('用户提问数 %d' % author.question_num) print('用户答题数 %d' % author.answer_num) print('用户专栏文章数 %d,名称分别为:' % author.post_num) for column in author.columns: print(column.name) print('用户收藏夹数 %d,名称分别为:' % author.collection_num) for collection in author.collections: print(collection.name) question = client.question('http://www.zhihu.com/question/28092572') for answer in question.answers: answer.save()
USER_URL = "https://www.zhihu.com/people/7sdream" FOLLOWER_CHECK_MAX_NUM = 2000 ANSWER_CHECK_MAX_NUM = 20 # ============================== def is_zero_user(author): return (author.upvote_num + author.question_num + author.answer_num) <= 3 client = ZhihuClient('test.json') user = client.author(USER_URL) print("检查用户{user.name} at {time}".format(user=user, time=datetime.datetime.now())) if user.follower_num < FOLLOWER_CHECK_MAX_NUM: FOLLOWER_CHECK_MAX_NUM = user.follower_num print("正在检查前{FOLLOWER_CHECK_MAX_NUM}个关注者....".format(**locals())) zeros = 0 for _, follower in zip(range(FOLLOWER_CHECK_MAX_NUM), user.followers): if is_zero_user(follower): zeros += 1 rate = zeros / FOLLOWER_CHECK_MAX_NUM print("{user.name}最近{FOLLOWER_CHECK_MAX_NUM}个关注者中,三无用户{zeros}个,占比{rate:.2%}".format(**locals()))