pithyone / zhihu-crawler
轻量级知乎爬虫
3.5.0
2018-12-19 09:03 UTC
Requires
- php: >=5.5.0
- ext-json: *
- fabpot/goutte: ^3.2
Requires (Dev)
- phpunit/phpunit: ^4.8.35 || ^5.7 || ^6.4 || ^7.0
README
ZhihuCrawler 是一个知乎轻量级爬虫,支持问题、收藏夹和本月最热。
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()); }