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();
}
}
}
...全文
相关推荐
java实现一个简单的网络爬虫代码示例
在本文中,我们将介绍如何使用Java实现一个简单的网络爬虫代码示例,并使用Jsoup解析HTML页面。知识点一:Java网络爬虫的基本概念网络爬虫是一种自动化程序,用于从互联网上提取数据。
网络爬虫编写常见问题
要编写爬虫程序,首先必须找一个爬虫框架,如果你使用Python语言,可以选用scrapy,如果你使用Java语言,可选用WebMagic,本文使用后者,编写爬虫程序无非分以下几步: 根据URL下载网页,得到HTML(注意并不是通过开发工具看到的HTML,而是网页源代码HTML,这两者有本质区别); 根据HTML解析您所需要的数据,可以利用xpath获取DOM节点内容或属性值; 有可能还需要根据得到的HTML解析出其他链接,利用多线程继续爬取; 解析后的数据存储(数据库,文件等); WebMagic爬虫框架在
一个用java语言编写的网络爬虫程序
网络爬虫,又称为网页蜘蛛或网络机器人,是一种自动浏览互联网并抓取网页信息的程序。
java网络爬虫
网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本。另外一些不常使用的名字还有蚂蚁、自动索引、模拟程序或者蠕
网络爬虫网络爬虫
网络爬虫,也被称为网页蜘蛛或网络机器人,是自动化地浏览互联网并抓取网页信息的程序。



