Пример #1
0
    def setUpClass(cls):
        url = 'http://zhuanlan.zhihu.com/xiepanda/20202275'

        post_path = os.path.join(TEST_DATA_PATH, 'column_post.json')
        with open(post_path, 'r') as f:
            post_json = json.load(f)

        post_saved_path = os.path.join(TEST_DATA_PATH, 'post.md')
        with open(post_saved_path, 'rb') as f:
            cls.post_saved = f.read()

        cls.post = Post(url)
        cls.post.soup = post_json
        cls.expected = {
            'column_in_name': 'xiepanda',
            'slug': 20202275,
            'column_name': '谢熊猫出没注意',
            'author_name': '谢熊猫君',
            'author_id': 'xiepanda',
            'title': '为了做一个称职的吃货,他决定连着吃一百天转基因食物',
            'upvote_num': 963,
            'comment_num': 199
        }
Пример #2
0
def post_test(post_url):
    post = Post(post_url)

    # 获取该文章的标题
    title = post.get_title()
    # 获取该文章的内容
    content = post.get_content()
    # 获取该文章的作者
    author = post.get_author()
    # 获取该文章的所属专栏
    column = post.get_column()
    # 获取该文章所属话题
    topics = post.get_topics()

    print title  # 输出:
    print content
    for topic in topics:
        print topic,  # 输出:
    print "\n"
    print author
    # 输出:<zhihu.User instance at 0x7f8b6582d0e0>
    # User类对象
    print column
Пример #3
0
def post_test(post_url):
    post = Post(post_url)
    
    # 获取该文章的标题
    title = post.get_title()
    # 获取该文章的内容
    content = post.get_content()
    # 获取该文章的作者
    author = post.get_author()
    # 获取该文章的所属专栏
    column = post.get_column()
    # 获取该文章所属话题
    topics = post.get_topics()
    
    print title  # 输出:
    print content
    for topic in topics:
        print topic,  # 输出:
    print "\n"
    print author  
    # 输出:<zhihu.User instance at 0x7f8b6582d0e0>
    # User类对象
    print column