博客列表 >php爬图片

php爬图片

南鸢离梦的博客
南鸢离梦的博客原创
2019年12月24日 10:44:441051浏览

composer 安装 QueryList

composer require jaeger/querylist

  1. <?php
  2. namespace app\index\controller;
  3. use QL\QueryList;
  4. use think\facade\View;
  5. class Index
  6. {
  7. public function index()
  8. {
  9. for ($i=2;$i<5;$i++){
  10. $ql = QueryList::get("https://mm.enterdesk.com/$i.html");
  11. $images[] = $ql->find('.egeli_pic_dl>dd>a>img')->attrs('src')->toArray();
  12. }
  13. foreach ($images as $k => $v){
  14. foreach ($v as $j => $l){
  15. $newImg[] = $l;
  16. }
  17. }
  18. dump($newImg);
  19. View::assign('num',sizeof($newImg));
  20. View::assign('images',$newImg);
  21. return View::fetch('index');
  22. }
  23. }
  24. <!DOCTYPE html>
  25. <html lang="en">
  26. <head>
  27. <meta charset="UTF-8">
  28. <title>Title</title>
  29. <style>
  30. body{
  31. margin: 0;
  32. padding: 0;
  33. }
  34. ul{
  35. padding: 0;
  36. }
  37. li{
  38. display: inline-block;
  39. width: 23.5%;
  40. margin: 0 auto;
  41. padding: 10px;
  42. }
  43. img{
  44. margin: 0;
  45. width: 100%;
  46. }
  47. </style>
  48. </head>
  49. <body>
  50. <ul>
  51. <input type="hidden" id="num" value="{$num}">
  52. {volist name="images" id="v"}
  53. <li><img src="{$v}" alt=""></li>
  54. {/volist}
  55. </ul>
  56. <script>
  57. window.onload=function()
  58. {
  59. var num = document.getElementById("num").value;
  60. alert('本次爬虫爬到了'+num+'张图片')
  61. }
  62. </script>
  63. </body>
  64. </html>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议