论坛首页 编程语言技术论坛

企业选择爬虫代理的重要因素

浏览 255 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2021-10-27  
网络爬虫是大数据时不可以缺少的一种行业,互联网上的数据非常大,所以采集数据必须依靠网络爬虫。爬虫的使用不仅是个人,大多数企业的需求量也很大,所以爬虫在采集过程中会发出大量请求,任何目标网站都是会禁止服务器大量请求的,并且会进行所封爬虫或封IP的行为,也就是网站的“反爬虫”机制。
应对这种爬虫阻碍最简单的方式就是使用代理IP,常用的方法就是用亿牛云爬虫代理IP来更换,但是代理IP也有很多种类型,不同类型的代理IP适合不同的场景,而最适合爬虫的专门提供的爬虫代理。
一些选择代理的重要因素分享给大家:
1、IP池大的代理商,需要的数据越多,ip池越大越好。
2、覆盖地区广的代理IP,爬虫代理IP池地区覆盖越广,长期更加稳定
3、选择稳定性高的爬虫代理IP,最好是测试对比稳定性
4、支持大量并发的爬虫代理,比如爬虫加强版
5、一定要选择家庭私密真实IP,延迟会更低,速度更快。
简单的爬虫程序里面代理的使用方式,这里以动态转发为例:
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;

import java.io.IOException;

public class Main {
    # 代理服务器(产品官网 www.16yun.cn)
    private static final String PROXY_HOST = "t.16yun.cn";
    private static final int PROXY_PORT = 31111;

    public static void main(String[] args) {
        HttpClient client = new HttpClient();
        HttpMethod method = new GetMethod("https://httpbin.org/ip");

        HostConfiguration config = client.getHostConfiguration();
        config.setProxy(PROXY_HOST, PROXY_PORT);

        client.getParams().setAuthenticationPreemptive(true);

        String username = "16ABCCKJ";
        String password = "712323";
        Credentials credentials = new UsernamePasswordCredentials(username, password);
        AuthScope authScope = new AuthScope(PROXY_HOST, PROXY_PORT);

        client.getState().setProxyCredentials(authScope, credentials);

        try {
            client.executeMethod(method);

            if (method.getStatusCode() == HttpStatus.SC_OK) {
                String response = method.getResponseBodyAsString();
                System.out.println("Response = " + response);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            method.releaseConnection();
        }
    }
}
示例是实际测试可以用的,有需要的可以实践学习学习。
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics