The example in this article describes how CodeIgniter implements the method of capturing images from the website and automatically downloading them to the folder. methods in the folder. Share it with everyone for your reference. The details are as follows:
Because a certain website is quite tricky to view pictures, so I have to turn page by page. . . . so. . . . This is what I wrote
(I am a product, not a programmer) The running speed is simply unbearable, and errors often occur, so I hope everyone can help improve it (PHP).
Of course you are also welcome to see the PYTHON and GOLANG versions~~^_^
1. controllers:
$this->load->helper('date'); $this->load->helper('phpQuery'); //我是把phpQuery单文件放到helper里了
2. view:
This is just to quickly produce products, so if you write the code directly in VIEW, please ignore the variable name. . .
<?php $imageslist = phpQuery::newDocumentFile('http://g.e-hentai.org/g/xxxxx/xxxxxxx/'); //首页 $pn = 1;//页数 $ps = $imageslist->find('.ptt td a');//从首页抓页面导航 //从页面导航开始获取页面内容 foreach($ps as $p) { echo '第'.$pn++.'页:<a href="'.pq($p)->attr("href").'"/></br>'; $imagesnow = phpQuery::newDocumentFile(pq($p)->attr("href")); //单页内容 $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); } } ?>
I hope this article will be helpful to everyone’s PHP programming based on CodeIgniter.