Jsoup和HttpClient4.3设置代理爬内容

有时候由于不可抗力,我们爬外面的东西的时候需要设置代理,设置方法如下:

Jsoup

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 1080));
Connection connection = Jsoup.connect(url).proxy(proxy);

HttpClient4.3

CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet get = new HttpGet(moreUrl);
HttpHost proxy = new HttpHost("localhost", 1080);
RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
get.setConfig(config);
CloseableHttpResponse response = httpclient.execute(get);

参考: https://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientProxyAuthentication.java

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券