>  기사  >  백엔드 개발  >  爬小说站

爬小说站

WBOY
WBOY원래의
2016-07-25 08:50:311196검색
给老婆大人看小说用的
原始站点总是弹窗,弹窗就弹窗吧,还有声音,声音还竟是哪种的

虽说可以用chrome屏蔽掉,也可写hosts,但是换个站点还的重新弄,怪麻烦的
  1. $base = 'http://xx/oo/';
  2. $start = 'xx.shtml';
  3. $content_grep = '/    (.*)
    /';
  4. $next_grep = '/href=\'(\d+\.shtml)\'>下一页/';
  5. $next = $start;
  6. $file_name = 'out.txt';
  7. while($next) {
  8. echo 'getting ' . $next . PHP_EOL;
  9. $result = file_get_contents($base . $next);
  10. preg_match_all($content_grep, $result, $match);
  11. $isTitle = true;
  12. $content = "";
  13. foreach($match[1] as $line) {
  14. if($isTitle) {
  15. $content = $line . PHP_EOL . PHP_EOL;
  16. $isTitle = false;
  17. } else {
  18. $content .= ' ' . $line . PHP_EOL . PHP_EOL;
  19. }
  20. }
  21. $file = fopen($file_name, 'a');
  22. echo 'write length: ' . strlen($content) . PHP_EOL;
  23. fwrite($file, $content);
  24. fclose($file);
  25. echo '.';
  26. preg_match($next_grep, $result, $match);
  27. $next = $match[1];
  28. }
复制代码


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:php5.3连接sqlserver2005 다음 기사:php 的常用函数