之前看到有人用go来写了爬虫爬HD美女照,拿来用发现用不了,里面有api接口,于是拿来写了个php版本的。php只要安装了curl扩展都没问题。我拿来爬了一下,九百多张。
<?php /** * curl多线程下载类 */ class MultiHttpRequest { public $urls = array (); private $res = array (); private $curlopt_header = 0; private $method ="GET"; private $curlopt = array (); public function __construct($urls = false, $curlopt = array ()) { $this->urls = $urls; if ( !empty($curlopt) ) { $this->curlopt = $curlopt; } } public function set_urls($urls) { $this->urls = $urls; return $this; } public function set_curlopt($name, $vale) { $this->curlopt[$name] = $vale; } public function is_return_header($b) { $this->curlopt_header = $b; return $this; } public function get_curlopt() { return $this->curlopt; } public function set_method($m) { $this->medthod = strtoupper($m); return $this; } public function set_curlopts($arr) { $this->curlopt = $arr; } public function start() { if ( !is_array($this->urls) || count($this->urls) == 0 ) { return false; } $handle = curl_multi_init(); foreach ( $this->urls as $k => $v ) { $curl[$k] = $this->add_handle($handle, $v); } $this->exec_handle($handle); foreach ( $this->urls as $k => $v ) { $this->res[$k] = curl_multi_getcontent($curl[$k]); curl_multi_remove_handle($handle, $curl[$k]); } curl_multi_close($handle); } private function add_handle($handle, $url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); foreach ( $this->curlopt as $k => $v ) { curl_setopt($curl, $k, $v); } curl_multi_add_handle($handle, $curl); return $curl; } private function exec_handle($handle) { $flag = null; do { curl_multi_exec($handle, $flag); } while ( $flag > 0 ); } public function getRes() { return $this->res; } } class HDbutifulyGril { private $url = ''; private $savepath = ''; private $imagessavepath = array(); public function __construct($url,$savepath='') { $this->url = $url; if( !empty($savepath) && !is_dir($savepath)){ mkdir($savepath,0777,true); } $this->savepath = $savepath; } /** * 得到所有大图的url地址 * @param type $id * @return array(); */ private function getimagesurl($id = '') { $url = $this->url . $id; $str = file_get_contents($url); $arr = json_decode($str, true); $images = array (); $savepath = array(); if ( is_array($arr) && !empty($arr) ) { foreach ( $arr['data'] as $v ) { $url = $v['image']['original']; $filename = $this->getFilenameBy($url); if( !file_exists($filename)){ // 如果图片已经采集了就不要再采了 $images[] = $url; $savepath[] = $filename; } } } $this->imagessavepath = $savepath; return $images; } /** * 通过url确定图片的保存地址 * @param string $url * @return string */ private function getFilenameBy($url) { $tmp = explode('/', $url); return $this->savepath . str_replace(',', '_', array_pop($tmp)); } /** * 开始下载 * @param int $id pid */ public function start($id = '') { $imgurl = $this->getimagesurl($id); $imgs = $this->MultiDownByUrls($imgurl); foreach ( $imgs as $k => $v ) { if ( !empty($v) ) { file_put_contents($this->imagessavepath[$k], $v); } } } /** * 通过urls多线程下载图片 * @param array $urls * @return array */ private function MultiDownByUrls($urls) { $opts = array ( CURLOPT_RETURNTRANSFER => 1, CURLOPT_AUTOREFERER => 1, CURLOPT_HEADER => 0, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36' ); $mutil = new MultiHttpRequest($urls, $opts); $mutil->start(); return $mutil->getRes(); } } $url = 'http://api.lovebizhi.com/macos_v4.php?a=category&spdy=1&tid=3&order=hot&color_id=3&device=105&uuid=436e4ddc389027ba3aef863a27f6e6f9&mode=0&retina=0&client_id=1008&device_id=31547324&model_id=105&size_id=0&channel_id=70001&screen_width=1920&screen_height=1200&bizhi_width=1920&bizhi_height=1200&version_code=19&language=zh-Hans&jailbreak=0&mac=&p='; $savepath = __DIR__.DIRECTORY_SEPARATOR.'images' . DIRECTORY_SEPARATOR; $hd = new HDbutifulyGril($url,$savepath); for ( $i = 1; $i < 100; $i++ ) { $hd->start($i); }

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기
