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

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

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

Connection.execute介绍

[英]Execute the request.
[中]执行请求。

代码示例

代码示例来源:origin: RipMeApp/ripme

public Response response() throws IOException {
    Response response = null;
    IOException lastException = null;
    int retries = this.retries;
    while (--retries >= 0) {
      try {
        response = connection.execute();
        return response;
      } catch (IOException e) {
        logger.warn("Error while loading " + url, e);
        lastException = e;
      }
    }
    throw new IOException("Failed to load " + url + " after " + this.retries + " attempts", lastException);
  }
}

代码示例来源:origin: RipMeApp/ripme

.timeout(Utils.getConfigInteger("download.timeout", 60 * 1000))
.maxBodySize(1024 * 1024 * 100)
.execute();

代码示例来源:origin: RipMeApp/ripme

private String getImageLinkFromDLLink(String url) {
  try {
    Connection.Response response = Jsoup.connect(url)
        .userAgent(USER_AGENT)
        .timeout(10000)
        .cookies(cookies)
        .followRedirects(false)
        .execute();
    String imageURL = response.header("Location");
    LOGGER.info(imageURL);
    return imageURL;
    } catch (IOException e) {
      LOGGER.info("Got error message " + e.getMessage() + " trying to download " + url);
      return null;
    }
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

public static Observable<BaseDanmakuParser> downloadXML(final String uri) {
    return Observable.create((Observable.OnSubscribe<BaseDanmakuParser>) subscriber -> {
      if (TextUtils.isEmpty(uri)) {
        subscriber.onNext(new BaseDanmakuParser() {
          @Override
          protected IDanmakus parse() {
            return new Danmakus();
          }
        });
      }
      ILoader loader = null;
      try {
        HttpConnection.Response rsp = (HttpConnection.Response)
            Jsoup.connect(uri).timeout(20000).execute();
        InputStream stream = new ByteArrayInputStream(BiliDanmukuCompressionTools.
            decompressXML(rsp.bodyAsBytes()));
        loader = DanmakuLoaderFactory.
            create(DanmakuLoaderFactory.TAG_BILI);
        loader.load(stream);
      } catch (IOException | DataFormatException | IllegalDataException e) {
        e.printStackTrace();
      }
      BaseDanmakuParser parser = new BiliDanmukuParser();
      assert loader != null;
      IDataSource<?> dataSource = loader.getDataSource();
      parser.load(dataSource);
      subscriber.onNext(parser);
    }).subscribeOn(Schedulers.io());
  }
}

代码示例来源:origin: 4pr0n/ripme

.ignoreContentType()
            .connection()
            .execute().body();
jsonString = jsonString.replace("&quot;", "\"");
return new JSONObject(jsonString);

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

@Override
public String execute() {
  Map<String, Object> resMap = new HashMap<>();
  try {
    Connection.Response response = connection.execute();
    resMap.put("code", response.statusCode());
    resMap.put("message", response.statusMessage());
    resMap.put("body", response.body());
  } catch (IOException e) {
    e.printStackTrace();
    resMap.put("code", "-1");
    resMap.put("message", "Request Exception");
    resMap.put("body", "");
  }
  return gson.toJson(resMap);
}

代码示例来源:origin: BeelGroup/Docear-Desktop

private Map<String, String> requestNewCookie(String fileName) {		
  Map<String, String> cookies = null;
  try{
    Response response = getConnection(BaseURL).ignoreHttpErrors(true).execute();					
    cookies = response.cookies();
    String gsp = cookies.get("GSP");
    cookies.put("GSP", gsp + ":CF=4"); // :CF=4 enables the export to BibTex Link in the result list
    saveCookies(cookies, fileName);
  }catch(IOException e){
    logger.info(e.getMessage(), e);
  }
  return cookies;
}

代码示例来源:origin: AlexanderBartash/hybris-integration-intellij-idea-plugin

protected Response getResponseForUrl(String hacURL) {
  try {
    return connect(hacURL).method(Method.GET).execute();
  } catch (ConnectException ce) {
    return null;
  } catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
    LOG.warn(e.getMessage(), e);
    return null;
  }
}

代码示例来源:origin: calvinaquino/LNReader-Android

@Override
  protected AsyncTaskResult<Document> doInBackground(URL... arg0) {
    try {
      Log.d("DownloadPageTask", "Downloading: " + arg0[0].toString());
      Response response = Jsoup.connect(arg0[0].toString())
          .timeout(7000)
          .execute();
      Log.d("DownloadPageTask", "Complete: " + arg0[0].toString());
      return new AsyncTaskResult<Document>(response.parse(), Document.class);
    } catch (Exception e) {
      return new AsyncTaskResult<Document>(null, Document.class, e);
    }
  }
}

代码示例来源:origin: dimtion/Shaarlier

/**
 * Method which retrieve a token for posting links
 * Update the cookie, the token and the date
 * Assume being logged in
 */
private void retrievePostLinkToken(String encodedSharedLink) throws IOException {
  final String postFormUrl = this.mShaarliUrl + "?post=" + encodedSharedLink;
  Connection.Response postFormPage = this.createShaarliConnection(postFormUrl, false)
      .execute();
  final Element postFormBody = postFormPage.parse().body();
  // Update our situation :
  this.mToken = postFormBody.select("input[name=token]").first().attr("value");
  this.mDatePostLink = postFormBody.select("input[name=lf_linkdate]").first().attr("value"); // Date choosen by the server
  this.mSharedUrl = postFormBody.select("input[name=lf_url]").first().attr("value");
}

代码示例来源:origin: florent37/RxRetroJsoup

@Override
public void subscribe(ObservableEmitter<Connection.Response> observableEmitter) throws Exception {
  try {
    final Connection.Response response = jsoupConnection.execute();
    observableEmitter.onNext(response);
    observableEmitter.onComplete();
  } catch (Exception e) {
    observableEmitter.onError(e);
  }
}

代码示例来源:origin: avaire/avaire

private int getLatestComicNumber() {
    return ((Double) avaire.getCache().getAdapter(CacheType.FILE).remember("xkcd.latest", 720, () -> {
      try {
        Connection.Response response = Jsoup.connect("https://xkcd.com/info.0.json")
          .ignoreContentType(true).execute();

        return new JSONObject(response.body()).get("num");
      } catch (IOException e) {
        e.printStackTrace();
        return 1;
      }
    })).intValue();
  }
}

代码示例来源:origin: com.github.florent37/rxjsoup

@Override
public void subscribe(ObservableEmitter<Connection.Response> observableEmitter) throws Exception {
  try {
    final Connection.Response response = jsoupConnection.execute();
    observableEmitter.onNext(response);
    observableEmitter.onComplete();
  } catch (Exception e) {
    observableEmitter.onError(e);
  }
}

代码示例来源:origin: REDNBLACK/J-Kinopoisk2IMDB

public ExchangeObject(Connection.Request request, ResponseProcessor<OUT> responseProcessor) throws IOException {
  this.request = request;
  this.responseProcessor = responseProcessor;
  this.responseSupplier = rethrowSupplier(() -> Jsoup.connect(request.url().toString())
      .request(request)
      .execute()
  );
}

代码示例来源:origin: dimtion/Shaarlier

/**
 * Check the if website is a compatible shaarli, by downloading a token
 */
public boolean retrieveLoginToken() throws IOException {
  final String loginFormUrl = this.mShaarliUrl + "?do=login";
  try {
    Connection.Response loginFormPage = this.createShaarliConnection(loginFormUrl, false).execute();
    this.mCookies = loginFormPage.cookies();
    this.mToken = loginFormPage.parse().body().select("input[name=token]").first().attr("value");
  } catch (NullPointerException | IllegalArgumentException e) {
    return false;
  }
  return true;
}

代码示例来源:origin: avaire/avaire

private SemanticVersion getLatestVersion() {
  Object version = avaire.getCache().getAdapter(CacheType.FILE).remember("github.version", 1800, () -> {
    try {
      return Jsoup.connect("https://raw.githubusercontent.com/avaire/avaire/master/build.gradle")
        .execute().body().split("version = '")[1].split("'")[0];
    } catch (IOException e) {
      AvaIre.getLogger().error("Failed to get latest version from github", e);
      return null;
    }
  });
  if (version == null) {
    return null;
  }
  return new SemanticVersion(version.toString());
}

代码示例来源:origin: delthas/JavaSkype

private Response sendRequest(Method method, String apiPath, boolean absoluteApiPath, String... keyval) throws IOException {
 String url = absoluteApiPath ? apiPath : SERVER_HOSTNAME + apiPath;
 Connection conn = Jsoup.connect(url).maxBodySize(100 * 1024 * 1024).timeout(10000).method(method).ignoreContentType(true).ignoreHttpErrors(true);
 logger.finest("Sending " + method + " request at " + url);
 if (skypeToken != null) {
  conn.header("X-Skypetoken", skypeToken);
 } else {
  logger.fine("No token sent for the request at: " + url);
 }
 conn.data(keyval);
 return conn.execute();
}

代码示例来源:origin: Kaysoro/KaellyBot

public static Connection.Response getResponse(String url) throws IOException {
    return Jsoup.connect(url)
        .userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0")
        .referrer("http://www.google.com")
        .timeout(10000)
        .validateTLSCertificates(false)
        .execute();
  }
}

代码示例来源:origin: calvinaquino/LNReader-Android

private Response connect(String url, int retry) throws IOException {
  // allow to use its keystore.
  return Jsoup.connect(url).validateTLSCertificates(!getUseAppKeystore()).timeout(getTimeout(retry)).execute();
}

代码示例来源:origin: bluetata/crawler-jsoup-maven

static Map<String,String> connect() throws IOException{
    Connection.Response res = Jsoup.connect("https://www.facebook.com/login.php")
        .data("username", "dietime1943@hotmail.com", "password", "password")
        .timeout(30 * 1000)
        .userAgent("Mozilla/5.0")
        .method(Method.POST)
        .execute();
    Document doc = res.parse();
    System.out.println(doc);
    
    Map<String, String> loginCookies = res.cookies();
    String sessionId = res.cookie("SESSIONID");
    return loginCookies;
  }
}

相关文章