這篇文章主要介紹了CodeIgniter實(shí)現(xiàn)從網(wǎng)站抓取圖片并自動(dòng)下載到文件夾里的方法,實(shí)例分析了CodeIgniter網(wǎng)頁圖片操作的相關(guān)技巧,需要的朋友可以參考下
本文實(shí)例講述了CodeIgniter實(shí)現(xiàn)從網(wǎng)站抓取圖片并自動(dòng)下載到文件夾里的方法。分享給大家供大家參考。具體如下:
因?yàn)槟尘W(wǎng)站看圖比較坑爹,要一頁一頁的翻頁。。。。所以。。。。就寫了這么個(gè)東西
(我是產(chǎn)品不是程序員)運(yùn)行速度簡直無法忍受,而且經(jīng)常會(huì)有錯(cuò)誤發(fā)生,所以希望大家?guī)兔Ω倪M(jìn)(PHP)。
當(dāng)然也歡迎看到PYTHON,GOLANG的版本~~^_^
1. controllers:
- $this->load->helper('date');
- $this->load->helper('phpQuery');
- //我是把phpQuery單文件放到helper里了
2. view:
這里只是為了快速出產(chǎn)品,所以直接在VIEW里寫的代碼,請(qǐng)無視變量名。。。
- <?php
- $imageslist = phpQuery::newDocumentFile('http://g.e-hentai.org/g/xxxxx/xxxxxxx/');
- //首頁
- $pn = 1;//頁數(shù)
- $ps = $imageslist->find('.ptt td a');//從首頁抓頁面導(dǎo)航
- //從頁面導(dǎo)航開始獲取頁面內(nèi)容
- foreach($ps as $p)
- {
- echo '第'.$pn++.'頁:<a href="'.pq($p)->attr("href").'"/></br>';
- $imagesnow = phpQuery::newDocumentFile(pq($p)->attr("href"));
- //單頁內(nèi)容
- $images = $imagesnow->find('#gdt a');//抓取圖片頁列表
- foreach($images as $image)
- {
- echo '<a href="'.pq($image,$imagesnow)->attr("href").'"/></br>';
- $imagebigs = phpQuery::newDocumentFile(pq($image,$imagesnow)->attr("href"));
- //獲取單圖片頁地址
- echo '<img src="'.$imagebigs->find('#i3 img')->attr('src').'"></br>';//輸出圖片
- ob_start();
- readfile($imagebigs->find('#i3 img')->attr('src'));
- $img = ob_get_contents();
- ob_end_clean();
- $filename='img/'.now().'.jpg';
- $f=fopen($filename,'a');
- fwrite($f,$img);
- fclose($f);
- }
- }
- ?>
希望本文所述對(duì)大家基于CodeIgniter的php程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答