php爬美女照
php
之前看到有人用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); }
登录后复制
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前
By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
击败分裂小说需要多长时间?
3 周前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保护它?
3 周前
By DDD

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PHP 8.4 带来了多项新功能、安全性改进和性能改进,同时弃用和删除了大量功能。 本指南介绍了如何在 Ubuntu、Debian 或其衍生版本上安装 PHP 8.4 或升级到 PHP 8.4

CakePHP 是 PHP 的开源框架。它的目的是使应用程序的开发、部署和维护变得更加容易。 CakePHP 基于类似 MVC 的架构,功能强大且易于掌握。模型、视图和控制器 gu

Visual Studio Code,也称为 VS Code,是一个免费的源代码编辑器 - 或集成开发环境 (IDE) - 可用于所有主要操作系统。 VS Code 拥有针对多种编程语言的大量扩展,可以轻松编写
