Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 def __init__(self, url):
     Zhihu.__init__(self)
     self.url = url
     self.profile_url = self.url + '/about'
     self.url_suffix = re.match(r'.+/people/(.+)', self.url).group(1)
     self.ask_url = self.url + '/asks'
     self.answer_url = self.url + '/answers'
     self.post_url = self.url + '/posts'
     self.collection_url = self.url + '/collections'
     self.edit_url = self.url + '/logs'
     self.ask_number = None
     self.answer_number = None
     self.post_number = None
     self.collection_number = None
     self.edit_number = None
Ejemplo n.º 5
0
 def __init__(self, url, session = None, soup = None):
     Zhihu.__init__(self, session, soup)
     self.url = url
     self.profile_url = self.url + '/about'
     self.url_suffix = re.match(r'.+/people/(.+)', self.url).group(1)
     self.ask_url = self.url + '/asks'
     self.answer_url = self.url + '/answers'
     self.post_url = self.url + '/posts'
     self.collection_url = self.url + '/collections'
     self.edit_url = self.url + '/logs'
     self.ask_number = None
     self.answer_number = None
     self.post_number = None
     self.collection_number = None
     self.edit_number = None
Ejemplo n.º 6
0
 def test_send_message_with_no_kwargs(self):
     """
     不带关键字参数,抛出异常
     :return:
     """
     zhihu = Zhihu()
     self.assertRaises(ZhihuError, zhihu.send_message, "hello")
Ejemplo n.º 7
0
 def test_follow_with_no_kwargs(self):
     """
     不带关键字参数,抛出异常
     :return:
     """
     time.sleep(1)
     zhihu = Zhihu()
     self.assertRaises(ZhihuError, zhihu.unfollow)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
import json

from zhihu import Zhihu
from zhihu import Answer
from zhihu import Account
from zhihu.url import URL
from constants import USER_LIST, DATA_PATH
"""
先登陆,存cookies
"""
# 我的已经登录好了
# account = Account()
# account.login("youremail", "yourpassword")

zhihu = Zhihu()
# print(zhihu.cookies)

# 获取用户基本信息
'''
profile = zhihu.profile(user_slug="huangkan")
print(profile)
with open("./profile.json", "w", encoding="utf-8") as f:
    f.write(json.dumps(profile, ensure_ascii=False))
'''

# 粉丝数量
'''
for i in range(10):
    follower_list = zhihu.followers(user_slug="huangkan", limit=100, offset=0)
    with open("./followers_{0}.json".format(i), "w", encoding="utf-8") as f:
Ejemplo n.º 10
0
# 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")
Ejemplo n.º 11
0
from zhihu import Answer


def vote_up_with_id():
    data = Answer(id=14005147).vote_up()
    print(data)


from zhihu.models import Model
from zhihu.models.account import Account

import logging

logging.basicConfig(level=logging.INFO)

if __name__ == '__main__':
    # vote_up_with_id()

    # model = Account()
    # model.login("*****@*****.**", "ssss")
    # model.login("158", "xxxx")

    from zhihu import Zhihu

    zhihu = Zhihu()
    print(zhihu)
    profile = zhihu.user(user_slug="xiaoxiaodouzi")
    print(profile)
Ejemplo n.º 12
0
 def __init__(self, url):
     Zhihu.__init__(self)
     self.url = url
     # self.soup = None
     self.answer_number = None
Ejemplo n.º 13
0
#     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)
Ejemplo n.º 14
0
 def __init__(self, url, session = None, soup = None):
     Zhihu.__init__(self, session, soup)
     self.url = url
     self.vote_number = None
Ejemplo n.º 15
0
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
    #
Ejemplo n.º 16
0
 def __init__(self, url):
     Zhihu.__init__(self)
     self.url = url
     # self.soup = None
     self.answer_number = None
Ejemplo n.º 17
0
# 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/xiaoxiaodouzi")
    # 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")
Ejemplo n.º 18
0
# encoding: utf-8
__author__ = 'liuzhijun'
import time
from zhihu import Zhihu

if __name__ == '__main__':
    zhihu = Zhihu()
    profile = zhihu.user(
        profile_url="https://www.zhihu.com/people/xiaoxiaodouzi")
    time.sleep(1)
    profile = zhihu.user(user_slug="xiaoxiaodouzi")
    time.sleep(1)
    _id = profile.get("id")
    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)
Ejemplo n.º 19
0
 def __init__(self, url):
     Zhihu.__init__(self)
     self.url = url
     self.vote_number = None
Ejemplo n.º 20
0
 def test_with_slug(self):
     followers = Zhihu().followers(user_slug="zhang-jia-wei")
     self.assertIn("follower_count", followers[0])
     self.assertIsNotNone(followers)
Ejemplo n.º 21
0
 def __init__(self, url):
     Zhihu.__init__(self)
     self.url = url
     self.vote_number = None