org.jsoup.Connection.proxy()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(3.2k)|赞(0)|评价(0)|浏览(184)

本文整理了Java中org.jsoup.Connection.proxy()方法的一些代码示例,展示了Connection.proxy()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connection.proxy()方法的具体详情如下:
包路径:org.jsoup.Connection
类名称:Connection
方法名:proxy

Connection.proxy介绍

[英]Set the HTTP proxy to use for this request.
[中]设置用于此请求的HTTP代理。

代码示例

代码示例来源:origin: YuanKJ-/JsCrawler

protected void processProxy(MyRequestModel model) {
  if (model.getProxy() != null) {
    String[] proxy = model.getProxy().split(":");
    if (proxy.length > 1) {
      // connection是jsoup请求的关键对象
      connection.proxy(proxy[0], Integer.parseInt(proxy[1]));
    }
  }
}

代码示例来源:origin: yy1193889747/springboot-demo

/**
 * 代理Ip爬取
 */
// @Scheduled(fixedRate = 10 * 60 * 1000)
public void ipProxy() throws IOException {
  Document doc = Jsoup.connect(URL_IP).userAgent(USER_AGENT).get();
  Elements ips = doc.select("body > div:nth-child(8) > ul > li:nth-child(2) > ul.l2").next();
  log.info("ip个数:{}", ips.size());
  for (int i = 0; i <= ips.size(); i++) {
    String ipaddr = ips.select("ul:nth-child(" + (i + 2) + ") > span:nth-child(1) > li").text();
    String proxy = ips.select("ul:nth-child(" + (i + 2) + ") > span:nth-child(2) > li").text();
    String speed = ips.select("ul:nth-child(" + (i + 2) + ") > span:nth-child(8) > li").text();
    log.info("ip: {}----端口: {} ----速度:{} ", ipaddr, proxy, speed);
    if (!"".equals(proxy)) {
      try {
        Jsoup.connect(URL_BLOG).proxy(ipaddr, Integer.parseInt(proxy)).ignoreHttpErrors(false).timeout(3000).get();
      } catch (IOException e) {
        log.info("不能用");
      }
    }
  }
}

代码示例来源:origin: zc-zh-001/ShadowSocks-Share

protected Connection getConnection(String url) {
  @SuppressWarnings("deprecation")
  Connection connection = Jsoup.connect(url)
      .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36")
      // .referrer("https://www.google.com/")
      .ignoreContentType(true)
      .followRedirects(true)
      .ignoreHttpErrors(true)
      .validateTLSCertificates(false)
      .timeout(TIME_OUT);
  if (isProxyEnable())
    connection.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(getProxyHost(), getProxyPort())));
  return connection;
}

代码示例来源:origin: indywidualny/FaceSlim

final Document response = Jsoup.connect(args[0])
    .userAgent(userAgent)
    .proxy(Miscellany.getProxy(preferences))
    .header("Accept-Encoding", "gzip, deflate")
    .timeout(5000)

代码示例来源:origin: indywidualny/FaceSlim

return Jsoup.connect(connectUrl)
    .userAgent(userAgent).timeout(JSOUP_TIMEOUT)
    .proxy(Miscellany.getProxy(preferences))
    .cookie("https://mobile.facebook.com", cm.getCookie("https://mobile.facebook.com"))
    .cookie("https://m.facebookcorewwwi.onion", cm.getCookie("https://m.facebookcorewwwi.onion"))

代码示例来源:origin: io.github.christian-draeger/page-content-tester

.referrer(params.getReferrer())
.proxy(createProxy(params.getProxy()))
.maxBodySize(0)
.timeout(params.getTimeout());

代码示例来源:origin: indywidualny/FaceSlim

message = Jsoup.connect(connectUrl)
    .userAgent(userAgent)
    .proxy(Miscellany.getProxy(preferences))
    .timeout(JSOUP_TIMEOUT)
    .cookie("https://m.facebook.com", cm.getCookie("https://m.facebook.com"))

代码示例来源:origin: xuxueli/xxl-crawler

conn.proxy(pageRequest.getProxy());

代码示例来源:origin: xuxueli/xxl-crawler

conn.proxy(pageRequest.getProxy());

相关文章