吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 5200|回复: 18
收起左侧

[其他原创] 多玩搞笑GIF图片爬虫 PHP实现

[复制链接]
changcha700 发表于 2019-11-6 11:20
本帖最后由 changcha700 于 2019-11-6 11:23 编辑

工作累了的时候总喜欢看看多玩搞笑GIF图,闲着没事写了个脚本把GIF图片保存到本地
代码也比较简单,需要的朋友可以下载看看,下面放上核心代码

重要提示:记得修改下面代码中的保存路径
代码中的第30行是保存路径

[PHP] 纯文本查看 复制代码
<?php
set_time_limit(0);
include 'Curl.php';

$curl = new Wenpeng\Curl\Curl();

$ids = array_unique(getPage($curl,30));
$logs = explode(',',file_get_contents('log.txt'));

foreach ($ids as $id) {
    if(is_numeric(array_search($id, $logs))){
        continue;
    }else{
        $url = 'http://tu.duowan.com/index.php?r=show/getByGallery/&gid='.$id;
        $data = $curl->url($url)->data();
        $source_data = json_decode($data, true);
        foreach ($source_data['picInfo'] as $value) {
            $parrent = '/[\\/:\*\?\"<>|]/';
            $filename = preg_replace($parrent, '', $value['add_intro']);
            
            if(isset($value['mp4_url']) && $value['mp4_url']!=''){
                $fina_url = $value['mp4_url'];
                $filename = $filename.'.mp4';
            }elseif(isset($value['source']) && $value['source']!=''){
                $fina_url = $value['source'];
                $filename = $filename.'.gif';
            }else{
                continue;
            }
            $curl->url($fina_url)->save('F:\images\\'.$filename);
        }
        file_put_contents('log.txt', $id.',',FILE_APPEND);
    }
}

echo "爬取完成";

//抓取内容页面
function getPage(Wenpeng\Curl\Curl $curl,int $offset){
    $url = 'http://tu.duowan.com/m/bxgif?offset='.$offset.'&order=created&math=0.6526874541027958';
    $data = $curl->url($url)->data();
    $html = json_decode($data,true)['html'];
    $parrent = '/gallery\/(\d*).html/i';
    $matchs = [];
    preg_match_all($parrent, $html,$matchs);
    $offset+=30;
    if(!empty($matchs[1])){
        return array_merge($matchs[1],getPage($curl,$offset));
    }else{
        return $matchs[1];
    }
}


执行方法,在根目录执行命令行,输入 php index.php即可
QQ截图20191106111800.jpg
QQ截图20191106111829.jpg


dw.rar (2.75 KB, 下载次数: 98)

免费评分

参与人数 4吾爱币 +3 热心值 +3 收起 理由
开创者 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
zimo650 + 1 + 1 谢谢@Thanks!
zhcxt + 1 + 1 热心回复!
lntuer + 1 life is short,i love Python!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

开创者 发表于 2019-11-6 13:57

可以搞一下,最近发现好多不错的博客。存文章太累了。都是高质量的,按文章内容测试都可以用,文章质量很高。,存下来学习就方便多了,以避免网站打不开了,找不到。

你有空了搞个吧,可惜我是不会,现在是验证一篇存一篇,累。

开创者 发表于 2019-11-6 13:48
不错,要是能改进改进就好了,最近在学wp.有没有办法把别人博客的文章这样给爬下来,最好是按标题为文件名,内容为文章内容的txt文件。同时记录一下文章来源网址在里面。方便使用的时间查找、
冬雪雨泉 发表于 2019-11-6 11:39
liudongxu110 发表于 2019-11-6 11:55
感谢分享
zhcxt 发表于 2019-11-6 12:00
感谢分享
头像被屏蔽
雨夜故园 发表于 2019-11-6 12:23
提示: 作者被禁止或删除 内容自动屏蔽
vethenc 发表于 2019-11-6 12:26
真香警告
chenlizhong 发表于 2019-11-6 12:28
学习了,感谢
709934831 发表于 2019-11-6 12:35
php果然是实际上最好的语言
ms8557 发表于 2019-11-6 12:36
回复的大多都是
程序猿
RobinMaas 发表于 2019-11-6 13:08
感谢分享!!!支持一下!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-20 10:36

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表