教你用PHP爬取王者荣耀英雄皮肤高清壁纸(附源码和壁纸)
发布时间:2023-06-05 01:30:06
今天看到一篇文章关于“用Python爬取王者荣耀官网的英雄皮肤图片”,于是顺手用laravel 也写了一个,在这里给大家分享一下,贴出源码:
1 public function getheroskin()
2 {
3 $heroApi = 'https://pvp.qq.com/web201605/js/herolist.json';
4 $response = Http::accept('application/json')->connectTimeout(3)->get($heroApi);
5 $heroArr = json_decode($response, true);
6 foreach ($heroArr as $v) {
7 $saveDir = 'heroskin/' . $v['cname'] . '/';
8 $i = 1;
9 while (true) {
10 $url = 'http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/' . $v['ename'] . '/' . $v['ename'] . '-bigskin-' . $i . '.jpg';
11 $headers = get_headers($url);
12 if (!strstr($headers[0], '200')) {
13 break;
14 }
15 try {
16 $client = new \GuzzleHttp\Client();
17 $data = $client->request('get', $url)->getBody()->getContents();
18 Storage::disk('local')->put($saveDir . $v['ename'] . '.jpg', $data);
19 } catch (\GuzzleHttp\RequestException $e) {
20 echo 'fetch fail';
21 }
22 $i++;
23 }
24 echo "下载==" . $v['cname'] . "==success\n";
25 }
26 }
获取全部皮肤壁纸,进下方公众号【码农编程进阶笔记】回复【王者荣耀】
如果喜欢,动动你那可爱的小手点个赞和回看吧