Giter VIP home page Giter VIP logo

zhihu_crawler's Introduction

免责声明:本项目涉及仅供学习交流使用。禁止将本项目或者Github源码用于任何商业目的。由此引发的任何法律纠纷与本人无关!

环境搭建好,拿来即用。支持获取知乎的关键词搜索、热榜、用户、回答、专栏文章、评论、关联关键词、关联文章等信息。代码思路来源于facebook_scraper

项目目录:

zhihu_crawler 核心代码区

  • __init__.py 为程序的对外统一入口
  • constants.py 常量
  • exceptions.py 自定义异常
  • extractors.py 数据清洗
  • page_iterators.py 页面处理
  • zhihu_scraper.py 页面请求、cookie设置
  • zhihu_types.py 类型提示、检查。项目自定义类型

common 重要参数的加密

zhihu_utils 工具包

注意事项 项目内有部分异步操作,在模块引用之前需要使用猴子补丁; 该项目已对核心参数进行了js逆向,但没有对ip限制、登录做针对性处理。 如有海量数据获取需求,可自行搭建IP池和cookie池。

安装:

pip install zhihu_crawler

使用案例:

# 猴子补丁
from gevent import monkey
monkey.patch_all()
from zhihu_crawler.zhihu_crawler import *

    if __name__ == '__main__':
        # 设置代理; 如采集量较大,建议每次请求都切换代理
        set_proxy({'http': 'http://127.0.0.1:8125', 'https': 'http://127.0.0.1:8125'})

        # 设置cookie
        set_cookie({'d_c0': 'AIBfvRMxmhSPTk1AffR--QLwm-gDM5V5scE=|1646725014'})

        # 搜索采集使用案例:
        for info in search_crawl(key_word='天空', nums=10):
            print(info)

        # 可传入data_type 指定搜索类型
        for info in search_crawl(key_word='天空', nums=10, data_type='answer'):
            print(info)

        # 用户信息回答列表使用案例(采集该用户信息及50条回答信息,每条回答包含50条评论):
        for info in user_crawler('wo-men-de-tai-kong',
                                 answer_nums=50,
                                 comment_nums=50
                                 ):
            print(info)

        # 用户信息提问列表使用案例(采集该用户信息及10条问题信息,每条问题包含10条回答,每条回答包含50条评论):
        for info in user_crawler('wo-men-de-tai-kong',
                                 question_nums=10,
                                 drill_down_nums=10,
                                 comment_nums=50
                                 ):
            print(info)

        # 热点问题采集使用案例
        # 采集 前10个问题, 每个问题采集10条回答
        for info in hot_questions_crawl(question_nums=10, drill_down_nums=10):
            print(info)

        # 可传入period 指定热榜性质。如小时榜、日榜、周榜、月榜
        # 传入domains 采集指定主题的问题
        for info in hot_questions_crawl(question_nums=10, period='day', domains=['1001', 1003]):
            print(info)

zhihu_crawler's People

Contributors

niuniujqkkk avatar su741448530 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.