CodeIgniter implements the method of grabbing images from the website and automatically downloading them to a folder, codeigniter grabbing_PHP tutorial

WBOY
Release: 2016-07-13 09:49:49
Original
966 people have browsed it

CodeIgniter implements the method of grabbing images from the website and automatically downloading them to the folder. codeigniter captures

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里了

Copy after login

2. view:

This is just to quickly produce products, so if you write the code directly in VIEW, please ignore the variable name. . .

<&#63;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);
  }
}
&#63;>
Copy after login

I hope this article will be helpful to everyone’s PHP programming based on CodeIgniter.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1018527.htmlTechArticleCodeIgniter realizes the method of grabbing images from the website and automatically downloading them to the folder. The codeigniter capture example in this article describes CodeIgniter implements grabbing images from websites and automatically downloading them to folders...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template