如何维护爬虫代理

2020-10-19 10:21:05 蜻蜓队长

为了保证网络爬虫再爬虫业务中能更高效稳定运行,在使用代理时需要维护一个好的爬虫代理IP池。那如何维护爬虫代理IP呢?

1、网上抓取免费代理

对爬取的代理ip进行验证,通过爬虫程序验证代理是否可用,把能用的代理IP列表。但是网上抓取的代理IP,可用性都很少,所以需要不间断的抓取代理IP,以保障自己的爬虫代理IP池有足够的代理IP使用。

2、购买动态隧道转发代理

网上抓取的免费代理可用率都很小。对爬虫业务使用没有实际的效果。想要让自己的爬虫业务能更加稳定的采集,这时候就需要在网上找一些优质代理商,进行高匿隧道转发爬虫代理IP购买。一般优质代理商的隧道转发代理IP都是过滤掉了无效IP,每个IP都是真实有效,通过隧道转发代理来填充自己的IP池,以保障自己的爬虫能稳定采集业务。

3、自建代理IP服务器

一般不愿意购买付费代理的,愿意花钱的,可以自己购买代理IP服务器来获取IP。

隧道转发代理维护:

<?php        namespace App\Console\Commands;        use Illuminate\Console\Command;    class Test16Proxy extends Command    {        /**         * The name and signature of the console command.         *         * @var string         */        protected $signature = 'test:16proxy';        /**         * The console command description.         *         * @var string         */        protected $description = 'Command description';        /**         * Create a new command instance.         *         * @return void         */        public function __construct()        {            parent::__construct();        }        /**         * Execute the console command.         *         * @return mixed         */        public function handle()        {            $client = new \GuzzleHttp\Client();            // 要访问的目标页面            $targetUrl = "http://httpbin.org/ip";            // 代理服务器(产品官网 www.16yun.cn)            define("PROXY_SERVER", "t.16yun.cn:31111");            // 代理身份信息            define("PROXY_USER", "username");            define("PROXY_PASS", "password");            $proxyAuth = base64_encode(PROXY_USER . ":" . PROXY_PASS);            $options = [                "proxy"  => PROXY_SERVER,                "headers" => [                    "Proxy-Authorization" => "Basic " . $proxyAuth                ]            ];            //print_r($options);            $result = $client->request('GET', $targetUrl, $options);            var_dump($result->getBody()->getContents());        }    } ?>

点击查看更多内容

以上内容来自于网络,如有侵权联系即删除
相关文章

上一篇: Mac下使用GitHub+Hexo搭建个人博客

下一篇: 为什么我不建议你用去 “ ! = null " 做判空?

客服紫薇:15852074331
在线咨询
客户经理