爬小說站

來源:互聯網
上載者:User
給老婆大人看小說用的
原始網站總是彈窗,彈窗就彈窗吧,還有聲音,聲音還竟是哪種的

雖說可以用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. }
複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.