Example #1
0
 private function getPostData(Crawler $node, $post_id, $href)
 {
     $tmp = [];
     $tmp['post_id'] = $post_id;
     //标题
     $tmp['title'] = trim($node->filter(".summary h2.title a")->text());
     //回答数
     $tmp['reply_num'] = intval(trim($node->filter(".qa-rank .answers")->text()));
     //浏览数
     $tmp['view_num'] = intval(trim($node->filter(".qa-rank .views")->text()));
     //投票数
     $tmp['vote_num'] = intval(trim($node->filter(".qa-rank .votes")->text()));
     //发布者
     $tmp['author'] = trim($node->filter(".author li a")->eq(0)->text());
     //发布时间
     $origin_time = trim($node->filter(".author li a")->eq(1)->text());
     if (mb_substr($origin_time, -2, 2, 'utf-8') == '提问') {
         $tmp['post_time'] = Util::parseDate($origin_time);
     } else {
         $tmp['post_time'] = Util::parseDate($this->getPostDateByDetail($href));
     }
     //收藏数
     $collect = $node->filter(".author .pull-right");
     if ($collect->count()) {
         $tmp['collect_num'] = intval(trim($collect->text()));
     } else {
         $tmp['collect_num'] = 0;
     }
     $tmp['tags'] = [];
     //标签列表
     $tags = $node->filter(".taglist--inline");
     if ($tags->count()) {
         $tmp['tags'] = $tags->filter(".tagPopup")->each(function (Crawler $node, $i) {
             return $node->filter('.tag')->text();
         });
     }
     $tmp['tag_num'] = count($tmp['tags']);
     return $tmp;
 }