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

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

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

Connection.cookie介绍

[英]Set a cookie to be sent in the request.
[中]设置要在请求中发送的cookie。

代码示例

代码示例来源:origin: malmstein/yahnac

private static Connection authorisedConnection(String baseUrlExtension, String userCookie) {
  return defaultConnection(baseUrlExtension).cookie("user", userCookie);
}

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

protected String getCsrfToken(@NotNull String hacURL, @NotNull String sessionId) {
  try {
    final Document doc = connect(hacURL).cookie("JSESSIONID", sessionId).get();
    final Elements csrfMetaElt = doc.select("meta[name=_csrf]");
    return csrfMetaElt.attr("content");
  } catch (IOException | NoSuchAlgorithmException | KeyManagementException e) {
    LOG.warn(e.getMessage(), e);
  }
  return null;
}

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

public static Document getRemoteURL(String remoteUrl) {
  Document doc = null;
  int temp = 0;
  try {
    temp = Integer.parseInt(Math.round(Math.random()*(UserAgent.length-1))+"");
    Connection conn = Jsoup.connect(remoteUrl);
    conn.header("User-Agent", UserAgent[temp]);
    conn.cookie("auth", "token");
    doc = conn.timeout(MAX_CONNECT_TIME).get();            
  } catch (Exception ex) {
    logger.error("GrabUnits.class_getRemoteURL 出现异常...");
    logger.error(ex);
  }
  
  try {
    int sleeptime = Integer.parseInt(Math.round(Math.random()*10000)+"");
    logger.info(BrowserType[temp] +" GET请求 " + remoteUrl + " 停留 " + sleeptime + " 毫秒。");
    Thread.sleep(sleeptime);
  } catch (InterruptedException ex) {
    logger.error("GrabUnits.class_getRemoteURL 休眠出现异常...");
    logger.error(ex);
  }        
  
  return doc;
}

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

/***
 * 远程访问URL返回Doc
 * @param remoteUrl
 * @return
 */
public static Document postRemoteURL(String remoteUrl) {
  Document doc = null;
  int temp = 0;
  try {
    temp = Integer.parseInt(Math.round(Math.random()*(UserAgent.length-1))+"");
    Connection conn = Jsoup.connect(remoteUrl);
    conn.header("User-Agent", UserAgent[temp]);
    conn.cookie("auth", "token");
    doc = conn.timeout(MAX_CONNECT_TIME).post();            
  } catch (Exception ex) {
    logger.error("GrabUnits.class_postRemoteURL 出现异常...");
    logger.error(ex);
  }
  
  try {
    int sleeptime = Integer.parseInt(Math.round(Math.random()*10000)+"");
    logger.info(BrowserType[temp] +" POST请求 " + remoteUrl + " 停留 " + sleeptime + " 毫秒。");
    Thread.sleep(sleeptime);
  } catch (InterruptedException ex) {
    logger.error("GrabUnits.class_postRemoteURL 休眠出现异常...");
    logger.error(ex);
  }
  
  return doc;
}

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

/**
 * Opens movie page using {@link Movie#imdbId}
 *
 * @param movie Movie which page should be opened
 * @throws IOException If an I/O error occurs
 */
@Override
public ExchangeObject<String> prepare(@NonNull Movie movie) throws IOException {
  val moviePageLink = new URL("http://www.imdb.com/title/" + movie.getImdbId());
  val request = HttpConnection.connect(moviePageLink)
      .userAgent(config.getString("user_agent"))
      .timeout(config.getInt("timeout"))
      .cookie("id", config.getString("auth"))
      .request();
  return new ExchangeObject<>(request, getResponseProcessor());
}

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

.userAgent(config.getString("user_agent"))
.timeout(config.getInt("timeout"))
.cookie("id", config.getString("auth"))
.ignoreContentType(true)
.data(postData)

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

/**
   * Sends POST request and adds Movie to IMDB list, using {@link Movie#imdbId}
   *
   * @param movie Movie which should be added to IMDB list
   * @throws IOException If an I/O error occurs
   */
  @Override
  public ExchangeObject<Integer> prepare(@NonNull Movie movie) throws IOException {
    val movieAddToWatchlistLink = new URL("http://www.imdb.com/list/_ajax/edit");

    val postData = new ImmutableMap.Builder<String, String>()
        .put("const", movie.getImdbId())
        .put("list_id", config.getString("list"))
        .put("ref_tag", "title")
        .build();

    val request = HttpConnection.connect(movieAddToWatchlistLink)
        .method(Connection.Method.POST)
        .userAgent(config.getString("user_agent"))
        .timeout(config.getInt("timeout"))
        .cookie("id", config.getString("auth"))
        .ignoreContentType(true)
        .data(postData)
        .request();

    return new ExchangeObject<>(request, new JSONPOSTResponseProcessor());
  }
}

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

Response post = Jsoup.connect(postUrl).data("PPFT", PPFT, "login", username, "passwd", password).cookie("MSPOK", MSPOK).maxBodySize(100 * 1024 * 1024).timeout(10000).method(Method.POST).followRedirects(false).ignoreContentType(true).ignoreHttpErrors(true).execute();
if (post.statusCode() != 302) {
 int index = post.body().indexOf("sErrTxt:'");

代码示例来源:origin: abc9070410/JComicDownloader

org.jsoup.nodes.Document doc = org.jsoup.Jsoup.connect(urlString.replaceFirst("[.]com[/]manhua-", ".com/rss-")).cookie("Cookie", "isAdult=1").parser(org.jsoup.parser.Parser.xmlParser()).get();
this.title = Common.getStringRemovedIllegalChar(NewEncoding.StoT(doc.getElementsByTag("title").get(0).text()));
for  (org.jsoup.nodes.Element e : doc.getElementsByTag("item")){

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

.header("Accept-Encoding", "gzip, deflate")
.timeout(5000)
.cookie("https://m.facebook.com", CookieManager.getInstance().getCookie("https://m.facebook.com"))
.get();

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

.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"))
    .get()
    .select("a.touchable")
return Jsoup.connect(connectUrl)
    .userAgent(userAgent).timeout(JSOUP_TIMEOUT)
    .cookie("https://mobile.facebook.com", cm.getCookie("https://mobile.facebook.com"))
    .get()
    .select("a.touchable")

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

.proxy(Miscellany.getProxy(preferences))
.timeout(JSOUP_TIMEOUT)
.cookie("https://m.facebook.com", cm.getCookie("https://m.facebook.com"))
.cookie("https://m.facebookcorewwwi.onion", cm.getCookie("https://m.facebookcorewwwi.onion"))
.get()
.select("div#viewport").select("div#page").select("div._129-")
.userAgent(userAgent)
.timeout(JSOUP_TIMEOUT)
.cookie("https://m.facebook.com", cm.getCookie("https://m.facebook.com"))
.get()
.select("div#viewport").select("div#page").select("div._129-")

代码示例来源:origin: com.github.houbb/paradise-enhance

/**
 * 发送翻译请求
 *
 * @param text       要翻译的内容
 * @param srcLang    源语言
 * @param targetLang 目标语言
 * @return 目标语言
 * @throws TranslatorException 翻译失败
 */
private String execute(final String text, final String srcLang,
            final String targetLang) throws TranslatorException {
  try {
    Document document = Jsoup.connect("https://translate.google.cn/")
        .data("sl", srcLang)
        .data("ie", "UTF-8")
        .data("oe", "UTF-8")
        .data("text", text)
        .data("tl", targetLang)
        .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36")
//                .cookie("Cookie", "Cookie PREF=ID=8daa1f767f10d1fe:U=f5ac701cf7d3f2e0:FF=0:LD=en:CR=2:TM=1277174286:LM=1289370601:S=q7yslRWEZs3uK1H8; NID=39=UO-TWo9HzzjHc-d_wYm7BVR1cH33KpqaN5h5877_i29nERA93FeG1GSuV3ZSvsOx8D-TnHKpB9m0KhZRH8U9uPwoE-arYd0bAyAlILyXZxLO2_TyGQhJpcMiOLVEuCpq; SID=DQAAAHoAAADMlGzeKhnGkbkIJ36tVO0ZPXgmQ6Cth7Oa6geyyE1WJooW8P01uKUHNrsRkjggvFMAWIWB9J5i18z0F6GjC_oV79mSwXEDGuRFGhRnDyJdid3ptjFW0pIyt4_2D6AMIqtOWF71aWdvY7IvAU1AWMNs8fBZHAOgRqtf3aCUkr36ZA; HSID=A6-YJTnhjBdFWukoR")
        .cookie("Cookie", "NID=101=IxXmFpFshaY43MPgpE-1LlE-CJUDmXHXaXk-yN13vShZ0VwfJb8AOefXmeRmfGWW3-56oCWYPQDXqcKNRrIuEubTZV4ZpO8nL6F1PZPDE0ILUVGzZuMxhNfarad0TM5-; _ga=GA1.3.109626246.1492094023")
        .timeout(2000000)
        .get();
    Element element = document.getElementById("result_box");
    return element.text();
  } catch (IOException e) {
    throw new TranslatorException(e);
  }
}

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

Jsoup.connect("").cookie("","").execute();

相关文章