從某網站抓取圖片並自動下載到檔案夾內

來源:互聯網
上載者:User
。。。。因為某網站看圖比較坑爹,要一頁一頁的翻頁。。。。所以。。。。就寫了這麼個東西
(我是產品不是程式員)運行速度簡直無法忍受,而且經常會有錯誤發生,所以希望大家幫忙改進(PHP)。。。
當然也歡迎看到PYTHON,GOLANG的版本~~^_^
對了,程式基於CodeIgniter
。。。。連結謹慎點擊
  1. $this->load->helper('date');
  2. $this->load->helper('phpQuery');
  3. //我是把phpQuery單檔案放到helper裡了
複製代碼
  1. //- -只是為了快速出產品,所以直接在VIEW裡寫的代碼,請無視變數名。。。
  2. $imageslist = phpQuery::newDocumentFile('http://g.e-hentai.org/g/xxxxx/xxxxxxx/');//首頁
  3. $pn = 1;//頁數
  4. $ps = $imageslist->find('.ptt td a');//從首頁抓頁面導航
  5. //從頁面導航開始擷取頁面內容
  6. foreach($ps as $p)
  7. {
  8. echo '第'.$pn++.'頁:attr("href").'"/>
    ';
  9. $imagesnow = phpQuery::newDocumentFile(pq($p)->attr("href"));//單頁內容
  10. $images = $imagesnow->find('#gdt a');//抓取圖片頁列表
  11. foreach($images as $image)
  12. {
  13. echo 'attr("href").'"/>
    ';
  14. $imagebigs = phpQuery::newDocumentFile(pq($image,$imagesnow)->attr("href"));//擷取單圖片頁地址
  15. echo 'find('#i3 img')->attr('src').'">
    ';//輸出圖片
  16. ob_start();
  17. readfile($imagebigs->find('#i3 img')->attr('src'));
  18. $img = ob_get_contents();
  19. ob_end_clean();
  20. $filename='img/'.now().'.jpg';
  21. $f=fopen($filename,'a');
  22. fwrite($f,$img);
  23. fclose($f);
  24. }
  25. }
  26. ?>
複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.