pithyone/zhihu-crawler

轻量级知乎爬虫

3.5.0 2018-12-19 09:03 UTC

This package is auto-updated.

Last update: 2024-10-20 01:28:47 UTC


README

ZhihuCrawler 是一个知乎轻量级爬虫,支持问题、收藏夹和本月最热。

Build Status codecov Minimum PHP Version Latest Stable Version License

Installation

composer require pithyone/zhihu-crawler

Usage

问题

<?php

require __DIR__ . '/../vendor/autoload.php';

$question = new \ZhihuCrawler\Question('290917836');

var_dump($question->getTitle());
var_dump($question->getDetail());
var_dump($question->getAnswerCount());

foreach ($question->getAnswerList() as $answer) {
    var_dump($answer->getTitle());
    var_dump($answer->getLink());
    var_dump($answer->getVoteCount());
    var_dump($answer->getAuthor());
    var_dump($answer->getAuthorLink());
    var_dump($answer->getAuthorBio());
    var_dump($answer->getSummary());
    var_dump($answer->getCreated());
}

收藏夹

<?php

require __DIR__ . '/../vendor/autoload.php';

$collection = new \ZhihuCrawler\Collection('41893350');

var_dump($collection->getTitle());
var_dump($collection->getDetail());

foreach ($collection->getAnswerList() as $answer) {
    var_dump($answer->getTitle());
    var_dump($answer->getLink());
    var_dump($answer->getVoteCount());
    var_dump($answer->getAuthor());
    var_dump($answer->getAuthorLink());
    var_dump($answer->getAuthorBio());
    var_dump($answer->getSummary());
    var_dump($answer->getCreated());
}

本月最热

<?php

require __DIR__ . '/../vendor/autoload.php';

$monthly = new \ZhihuCrawler\Monthly();

foreach ($monthly->getAnswerList() as $answer) {
    var_dump($answer->getTitle());
    var_dump($answer->getLink());
    var_dump($answer->getVoteCount());
    var_dump($answer->getAuthor());
    var_dump($answer->getAuthorLink());
    var_dump($answer->getAuthorBio());
    var_dump($answer->getSummary());
    var_dump($answer->getCreated());
}