owner888 / phpspider

《我用爬虫一天时间“偷了”知乎一百万用户,只为证明PHP是世界上最好的语言 》所使用的程序
3.49k stars 1.18k forks source link

在用回调函数on_list_page去获得列表页数据时候,无法真正add_url #162

Open qizhenchao opened 2 years ago

qizhenchao commented 2 years ago

在用回调函数on_list_page去获得列表页数据时候, $options = array( 'method' => 'get', 'context_data' => $page_views, );

$phpspider->add_url($content_url, $options);

这个方法不生效, 无法在content 页获得这个options 里的信息。 我猜想是这个$content_url已经在url列表里了, 无法重复再加入。

请问怎么解决这个问题?

qizhenchao commented 2 years ago

看了看源码,我觉得这里可以处理一下。 我可以改吗:)

    $exists = queue::exists($key); 
            // 不存在或者当前URL可重复入
            if (!$exists || $allowed_repeat) 
            {
                // 待爬取网页记录数加一
                queue::incr('collect_urls_num');
                // 先标记为待爬取网页
                queue::set($key, time()); 
                // 入队列
                $link = json_encode($link);
                //根据采集设置为顺序采集还是随机采集,使用列表或集合对象 2018-5 BY KEN <a-site@foxmail.com>
                if (self::$configs['queue_order'] == 'rand')
                {
                    queue::sadd('collect_queue', $link);
                }
                else
                {
                    queue::lpush('collect_queue', $link);
                }
                $status = true;
            }
owner888 commented 2 years ago

看了看源码,我觉得这里可以处理一下。 我可以改吗:)

    $exists = queue::exists($key); 
            // 不存在或者当前URL可重复入
            if (!$exists || $allowed_repeat) 
            {
                // 待爬取网页记录数加一
                queue::incr('collect_urls_num');
                // 先标记为待爬取网页
                queue::set($key, time()); 
                // 入队列
                $link = json_encode($link);
                //根据采集设置为顺序采集还是随机采集,使用列表或集合对象 2018-5 BY KEN <a-site@foxmail.com>
                if (self::$configs['queue_order'] == 'rand')
                {
                    queue::sadd('collect_queue', $link);
                }
                else
                {
                    queue::lpush('collect_queue', $link);
                }
                $status = true;
            }

可以呀, 改完给我提一个patch即可啊