用户:Laical查看:0 回复:0 评论:0 创建时间:2020-08-04T17:28:49
一、爬虫代理IP的基本用途
1、目前互联网的大部分网站做了反爬机制,爬虫大部分本机IP长时间访问该网站,网站给出了封IP的回应。这时候就需要http代理来进行对网站访问采集相关数据。
2、http代理可以加强爬虫对互联网的访问速度和频率。
3、使用http代理是为了避免喵自己的本机IP去采集数据。
4、互联网网站基本上都有反爬机制,一个IP长时间去访问就会出现爬虫限制。为了突破限制,就需要用到大量的爬虫代理IP。
二、互联网网站检查代理IP的几种方式1、反向检测:一般的家庭IP都不会有808080这种高端端口
2、HTTP请求头检测:只要是用了爬虫代理IP可以使用http代理请求头的方式去验证,假如其中包含XFF内容,肯定是使用了爬虫代理
3、检测端口:家庭IP中的端口一般不会大于10000,如果大于10000,有可能使用了爬虫代理。
三、如何验证代理IP存活有效性需要做代理IP存活检查的,建议不要访问百度或者其他网站,直接访问http://current.ip.16yun.cn:802,这个网站是专门检测代理IP存活
假如是用的代理IP访问此网站会显示代理IP,说明代理IP有效且用上了,如果显示本机IP说明代理IP无效
四、爬虫代理使用代码(JAVA)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(); } } }
总结:互联网网站的反爬机制都不相同,各种爬虫都面临封IP的情况,这种时候就可以使用亿牛云爬虫代理来解决这些封IP问题,来满足爬虫用户的需求。