def test_send_message_with_no_kwargs(self): """ 不带关键字参数,抛出异常 :return: """ zhihu = Zhihu() self.assertRaises(ZhihuError, zhihu.send_message, "hello")
def test_user_profile(self): """ 获取用户信息 :return: """ zhihu = Zhihu() profile = zhihu.user(user_slug="xiaoxiaodouzi") data = { 'avatar_url_template': 'https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_{size}.jpg', 'name': '我是小号', 'is_advertiser': False, 'url': 'http://www.zhihu.com/api/v4/people/1da75b85900e00adb072e91c56fd9149', 'gender': -1, 'user_type': 'people', 'url_token': 'xiaoxiaodouzi', 'headline': '程序员', 'avatar_url': 'https://pic1.zhimg.com/v2-ca13758626bd7367febde704c66249ec_is.jpg', 'is_org': False, 'type': 'people', 'badge': [], 'id': '1da75b85900e00adb072e91c56fd9149' } self.assertEqual(data, profile)
def test_follow_with_no_kwargs(self): """ 不带关键字参数,抛出异常 :return: """ time.sleep(1) zhihu = Zhihu() self.assertRaises(ZhihuError, zhihu.unfollow)
def test_unfollow_with_user_slug(self): """ 带user_slug,返回follower数量 :return: """ time.sleep(1) zhihu = Zhihu() data = zhihu.unfollow(user_slug="xiaoxiaodouzi") self.assertIn('follower_count', data)
def test_unfollow_with_url(self): """ 带url,返回follower数量 :return: """ time.sleep(1) zhihu = Zhihu() data = zhihu.unfollow(profile_url="https://www.zhihu.com/people/gao-yu-dong-41") self.assertIn('follower_count', data)
def run(): zhihu = Zhihu() # 热搜数据 searches, resp = zhihu.get_hot_search() if resp: saveRawContent(resp.text, 'hot-search', 'html') # 问题数据 questions, resp = zhihu.get_hot_question() if resp: text = util.cnsafe_json(resp.text) saveRawContent(text, 'hot-question', 'json') # 视频数据 videos, resp = zhihu.get_hot_video() if resp: text = util.cnsafe_json(resp.text) saveRawContent(text, 'hot-video', 'json') # 最新数据 todayMd = generate_readme(searches, questions, videos) saveReadme(todayMd) # 归档 archiveMd = generate_archive_md(searches, questions, videos) saveArchiveMd(archiveMd)
# encoding: utf-8 import time from zhihu import Zhihu __author__ = 'liuzhijun' if __name__ == '__main__': zhihu = Zhihu() profile = zhihu.user(profile_url="https://www.zhihu.com/people/zhijun-liu") print(profile) time.sleep(1) # profile = zhihu.user(user_slug="xiaoxiaodouzi") # time.sleep(1) # # _id = profile.get("id") # print(_id) # # 3a2be5588fefcbc13ba4459cd8f1b5bc # # 1da75b85900e00adb072e91c56fd9149 # zhihu.send_message("你好,问候1", profile_url="https://www.zhihu.com/people/xiaoxiaodouzi") # time.sleep(1) # zhihu.send_message("你好,问候2", user_slug="xiaoxiaodouzi") # time.sleep(1) # zhihu.send_message("你好,问候3", user_id=_id) # zhihu.follow(profile_url="https://www.zhihu.com/people/gao-yu-dong-41")
# print(data) logging.basicConfig(level=logging.INFO) if __name__ == '__main__': # vote_up_with_id() # from zhihu import Question # Question(id="60231684").unfollow_question() # Zhihu().login("+33752962193", "zhihudetail") # model.login("158", "xxxx") # from zhihu import Zhihu # # profile = Zhihu().user(user_slug="xiaoxiaodouzi") # # print(profile) # # from zhihu import Account # # account = Account() # account.register("续航小三", phone_num="+33752962193", password="******") # from zhihu.models.zhihu import Zhihu # data = Zhihu().profile(user_slug="pansz") # print(data) from zhihu import Zhihu data = Zhihu().followers(user_slug="pansz") print(data)
def test_with_slug(self): followers = Zhihu().followers(user_slug="zhang-jia-wei") self.assertIn("follower_count", followers[0]) self.assertIsNotNone(followers)
import logging from zhihu import Answer from zhihu import Account account = Account() # account.login("邮箱地址或者手机号码", "这里是密码") # account.login("+33752962193", "zhihudetail") from zhihu import Zhihu z = Zhihu() z.user(user_slug="liuzhijun001") def vote_up_with_id(): data = Answer(id=14005147).vote_up() print(data) logging.basicConfig(level=logging.INFO) if __name__ == '__main__': # vote_up_with_id() from zhihu import Question Question(id="60231684").unfollow_question() # Zhihu().login("+33752962193", "zhihudetail") # model.login("158", "xxxx") # from zhihu import Zhihu #