Jianshu.php 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace console\models\spider;
  3. class Jianshu extends SpiderAbstract
  4. {
  5. protected function filterContent($content = '')
  6. {
  7. // 图片全路径
  8. $content = preg_replace('#<img([\s\S]+?)src=\"(.*?)\?.*?\"[\s\S]*?>([\s\S]*?<div class=\"image-caption\">.*?</div>)?#', '', $content);
  9. // 去除链接
  10. $content = preg_replace('#<a([\s\S]+?)>(.*)?</a>#', '$2', $content);
  11. return $content;
  12. }
  13. protected function getCover($listNode)
  14. {
  15. $cover = strpos($listNode->parents('li')->filter('img')->attr('src'), 'http') === false ? $this->config['domain'].$listNode->parents('li')->filter('img')->attr('src') : $listNode->parents('li')->filter('img')->attr('src');
  16. $coverCon = file_get_contents($cover);
  17. $coverRootPath = \Yii::getAlias('@staticroot').'/';
  18. $coverFilePath = 'upload/image/'.date('Ymd').'/';
  19. $coverFileName = time().mt_rand(100000, 999999).'.jpg';
  20. if (!is_dir($coverRootPath.$coverFilePath)) {
  21. mkdir($coverRootPath.$coverFilePath, 0777, true);
  22. }
  23. file_put_contents($coverRootPath.$coverFilePath.$coverFileName, $coverCon);
  24. @chmod($coverRootPath.$coverFilePath, 0777);
  25. return $coverFilePath.$coverFileName;
  26. }
  27. }