新闻  |   论坛  |   博客  |   在线研讨会
使用高匿爬虫代理的安全性
laical | 2020-10-09 17:44:54    阅读:87   发布文章

互联网的发达,导致网上出现的网络爬虫也越来越多,伴随着爬虫对HTTP代理的需求也多了起来。刚开始的爬虫使用HTTP代理,对代理IP都不太信任,觉得很不安全。实际上不是这种。高匿的爬虫代理的安全性特别的好。在使用中不用担心安全问题,因为使用了代理以后,服务器的本机IP是处在一种隐藏状态,对方服务器看到的是代理服务器的IP。这就是越来越多的网络爬虫使用爬虫代理,它保证了客户隐私的安全。

HTTP代理类型:透明代理、普通代理、高匿代理

透明代理:无法隐藏本地IP

普通代理:对方服务器知道是使用了代理IP

高匿代理:隐藏本机IP,且对方无法知晓你是否使用了代理IP

使用高匿HTTP代理的好处:

1、提供网络爬虫采集速度。

2、隐藏本机IP

3、解决网站反爬策略

使用高匿名爬虫代理的方式:

<?php
    // 要访问的目标页面
    $url = "http://httpbin.org/ip";
    $urls = "https://httpbin.org/ip";

    // 代理服务器(产品官网 www.16yun.cn)
    define("PROXY_SERVER", "tcp://t.16yun.cn:31111");

    // 代理身份信息
    define("PROXY_USER", "username");
    define("PROXY_PASS", "password");

    $proxyAuth = base64_encode(PROXY_USER . ":" . PROXY_PASS);

    // 设置 Proxy tunnel
    $tunnel = rand(1,10000);

    $headers = implode("\r\n", [
        "Proxy-Authorization: Basic {$proxyAuth}",
        "Proxy-Tunnel: ${tunnel}",
    ]);
    $sniServer = parse_url($urls, PHP_URL_HOST);
    $options = [
        "http" => [
            "proxy"  => PROXY_SERVER,
            "header" => $headers,
            "method" => "GET",
            'request_fulluri' => true,
        ],
        'ssl' => array(
                'SNI_enabled' => true, // Disable SNI for https over http proxies
                'SNI_server_name' => $sniServer
        )
    ];
    print($url);
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    var_dump($result);

    // 访问 HTTPS 页面
    print($urls);
    $context = stream_context_create($options);
    $result = file_get_contents($urls, false, $context);
    var_dump($result);
?>


*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客