Grab images from a website and automatically download them to a folder

WBOY
Release: 2016-07-25 08:48:36
Original
1721 people have browsed it
. . . . Because a certain website is a bit tricky to view pictures, and you have to turn page after page. . . . so. . . . I just wrote something like this
(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~~^_^
By the way, the program is based on CodeIgniter
. . . . Click links carefully
  1. $this->load->helper('date');
  2. $this->load->helper('phpQuery');
  3. //I put the phpQuery single file into the helper
Copy code
  1. //- - Just to quickly produce products, so please ignore the variable names when writing code directly in VIEW. . .
  2. $imageslist = phpQuery::newDocumentFile('http://g.e-hentai.org/g/xxxxx/xxxxxxx/');//Homepage
  3. $pn = 1;//Number of pages
  4. $ps = $imageslist->find('.ptt td a');//Get the page navigation from the homepage
  5. //Get the page content starting from the page navigation
  6. foreach($ps as $p)
  7. {
  8. echo 'th'. $pn++.'Page:
    ';
  9. $imagesnow = phpQuery::newDocumentFile( pq($p)->attr("href"));//Single page content
  10. $images = $imagesnow->find('#gdt a');//Catch the image page list
  11. foreach($ images as $image)
  12. {
  13. echo '
    ';
  14. $ imagebigs = phpQuery::newDocumentFile(pq($image,$imagesnow)->attr("href"));//Get the address of a single image page
  15. echo '
    ';//Output image
  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. ?>
Copy code


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