Heim  >  Artikel  >  Backend-Entwicklung  >  爬小说站

爬小说站

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

虽说可以用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. }
复制代码


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:php5.3连接sqlserver2005 Nächster Artikel:php 的常用函数