不会正则下载暴漫好痛苦,唯一的正则是网上找的,最后还是用explode来处理了,小弟新人,求大牛改正。 无 ?php/** * 正则表达式匹配需要的图片 * @return ArrayIterator $arr */function pregIMG($str){//$str ='a href="/articles/7442969" target="_blank"i
不会正则下载暴漫好痛苦,唯一的正则是网上找的,最后还是用explode来处理了,小弟新人,求大牛改正。
<?php /** * 正则表达式匹配需要的图片 * @return ArrayIterator $arr */ function pregIMG($str){ //$str ='<a href="/articles/7442969" target="_blank"><img src="/static/imghwm/default1.png" data-src="http://www.68idc.cn/help/uploads/allimg/160322/2016161356-0.jpg" class="lazy" alt="没标题" style="max-width:90%" /></a>'; $pattern='/<img src="/static/imghwm/default1.png" data-src="http://www.68idc.cn/help/uploads/allimg/160322/2016162634-1.jpg" class="lazy" .+src=\"(.+\.jpg)\"?.+ alt="php不会正则的痛" >/i'; preg_match_all($pattern,$str,$matchs); return $matchs; } /** * 查找某个页面的jpg */ function getIMG($url,$dir){ if (empty($url)) return false; $contents = file_get_contents($url); $data = pregIMG($contents); $jpgs = $data[1]; unset($data); $data = array(); foreach ($jpgs as $k => $v){ $t = explode('/', $v); if ($t[3] == 'large'){ $data[$k] = $v; } } if(!file_exists($dir) || !is_dir($dir)){ mkdir($dir,0777); } $num = 1; foreach ($data as $v){ copy($v, $dir.'/'.time(). rand(10,100).'.jpg'); usleep(1); $num++; } return $num; } function getBaoZou($page=1){ $url = "http://baozoumanhua.com/tucao/fresh/page/".$page."?sv=1395827058"; $dir = "public"; return getIMG($url, $dir); } function getMoreBaoZou($page){ //下载前10页 $num = 0; for ($i = 1;$i < $page; $i++){ $num += getBaoZou($i); } echo '一共下载了'.$num.'张暴走漫画'; } getMoreBaoZou(10);//获取前10页的暴走漫画 ?>

Statement
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
What's New in Windows 11 KB5054979 & How to Fix Update Issues
3 weeks agoByDDD
How to fix KB5055523 fails to install in Windows 11?
2 weeks agoByDDD
InZoi: How To Apply To School And University
4 weeks agoByDDD
How to fix KB5055518 fails to install in Windows 10?
2 weeks agoByDDD
Roblox: Dead Rails – How To Summon And Defeat Nikola Tesla
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

WebStorm Mac version
Useful JavaScript development tools
