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

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

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

Connection.data介绍

[英]Get the data KeyVal for this key, if any
[中]获取此密钥的数据KeyVal(如果有)

代码示例

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

public Http data(Map<String,String> data) {
  connection.data(data);
  return this;
}
public Http data(String name, String value) {

代码示例来源:origin: ChinaSilence/any-video

/**
 * 调用腾讯接口,获取视频信息
 */
private String videoInfo(String vid) {
  try {
    Document document = Jsoup.connect(VIDEO_API).header("Cookie", COOKIE)
        .data("vids", vid).data("platform", PLATFORM)
        .data("sdtfrom", SDTFROM)
        .data("format", "10209")
        .data("otype", "json").data("defn", "fhd")
        .data("defaultfmt", "fhd").data("guid", GUID).ignoreContentType(true).get();
    String result = document.text().replace("QZOutputJson=", "");
    return result.substring(0, result.length() - 1);
  } catch (IOException e) {
    log.info("request tencent api error, vid : " + vid);
    throw new AnyException("request tencent api error, vid : " + vid);
  }
}

代码示例来源:origin: ChinaSilence/any-video

/**
   * 获取片段播放的 key
   */
  private String videoKey(String vid, String filename, String format) {
    try {
      Document document = Jsoup.connect(KEY_API).header("Cookie", COOKIE)
          .data("vid", vid).data("platform", PLATFORM)
          .data("otype", "json")
          .data("filename", filename).data("sdtfrom", SDTFROM)
          .data("format", format).data("guid", GUID).ignoreContentType(true).get();
      String result = document.text().replace("QZOutputJson=", "");
      System.out.println(result);
      result = result.substring(0, result.length() - 1);
      return JSONObject.parseObject(result).getString("key");
    } catch (IOException e) {
      log.info("request tencent video part api error, vid : " + vid);
      throw new AnyException("request tencent api error, vid : " + vid);
    }
  }
}

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

.userAgent(USER_AGENT)
    .timeout(5000)
    .data(postData)
    .post();
String jsonString = doc.toString();

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

private JSONArray getPageUrls() {
  String postURL = "http://www.tsumino.com/Read/Load";
  try {
    // This sessionId will expire and need to be replaced
    cookies.put("ASP.NET_SessionId","c4rbzccf0dvy3e0cloolmlkq");
    Document doc = Jsoup.connect(postURL).data("q", getAlbumID()).userAgent(USER_AGENT).cookies(cookies).referrer("http://www.tsumino.com/Read/View/" + getAlbumID()).get();
    String jsonInfo = doc.html().replaceAll("<html>","").replaceAll("<head></head>", "").replaceAll("<body>", "").replaceAll("</body>", "")
        .replaceAll("</html>", "").replaceAll("\n", "");
    JSONObject json = new JSONObject(jsonInfo);
    return json.getJSONArray("reader_page_urls");
  } catch (IOException e) {
    LOGGER.info(e);
    sendUpdate(RipStatusMessage.STATUS.DOWNLOAD_ERRORED, "Unable to download album, please compete the captcha at http://www.tsumino.com/Read/Auth/"
        + getAlbumID() + " and try again");
    return null;
  }
}

代码示例来源:origin: ChinaSilence/any-video

private Document requestAPI(String keyword) {
  try {
    return Jsoup.connect(api).userAgent(ua).ignoreContentType(true).data("wd", keyword).get();
  } catch (IOException e) {
    throw new AnyException(ExceptionEnum.VIDEO_SEARCH_ERROR);
  }
}

代码示例来源:origin: org.jsoup/jsoup

/**
 * Prepare to submit this form. A Connection object is created with the request set up from the form values. You
 * can then set up other options (like user-agent, timeout, cookies), then execute it.
 * @return a connection prepared from the values of this form.
 * @throws IllegalArgumentException if the form's absolute action URL cannot be determined. Make sure you pass the
 * document's base URI when parsing.
 */
public Connection submit() {
  String action = hasAttr("action") ? absUrl("action") : baseUri();
  Validate.notEmpty(action, "Could not determine a form action URL for submit. Ensure you set a base URI when parsing.");
  Connection.Method method = attr("method").toUpperCase().equals("POST") ?
      Connection.Method.POST : Connection.Method.GET;
  return Jsoup.connect(action)
      .data(formData())
      .method(method);
}

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

/**
 * Method which publishes a link to shaarli
 * Assume being logged in
 */
public void postLink(String sharedUrl, String sharedTitle, String sharedDescription, String sharedTags, boolean privateShare, boolean tweet)
    throws IOException {
  String encodedShareUrl = URLEncoder.encode(sharedUrl, "UTF-8");
  retrievePostLinkToken(encodedShareUrl);
  if (isUrl(sharedUrl)) { // In case the url isn't really one, just post the one chosen by the server.
    this.mSharedUrl = sharedUrl;
  }
  final String postUrl = this.mShaarliUrl + "?post=" + encodedShareUrl;
  Connection postPageConn = this.createShaarliConnection(postUrl, true)
      .data("save_edit", "Save")
      .data("token", this.mToken)
      .data("lf_tags", sharedTags)
      .data("lf_linkdate", this.mDatePostLink)
      .data("lf_url", this.mSharedUrl)
      .data("lf_title", sharedTitle)
      .data("lf_description", sharedDescription);
  if (privateShare) postPageConn.data("lf_private", "on");
  if (tweet) postPageConn.data("tweet", "on");
  postPageConn.execute(); // Then we post
}

代码示例来源:origin: Patreon/patreon-java

public TokensResponse getTokens(String code) throws IOException {
 Connection requestInfo = Jsoup.connect(PatreonAPI.BASE_URI + "/api/oauth2/token")
               .data("grant_type", GRANT_TYPE_AUTHORIZATION)
               .data("code", code)
               .data("client_id", clientID)
               .data("client_secret", clientSecret)
               .data("redirect_uri", redirectUri)
               .ignoreContentType(true);
 String response = requestInfo.post().body().text();
 return toObject(response, TokensResponse.class);
}

代码示例来源:origin: Patreon/patreon-java

public TokensResponse refreshTokens(String refreshToken) throws IOException {
 Connection requestInfo = Jsoup.connect(PatreonAPI.BASE_URI + "/api/oauth2/token")
               .data("grant_type", GRANT_TYPE_TOKEN_REFRESH)
               .data("client_id", clientID)
               .data("client_secret", clientSecret)
               .data("refresh_token", refreshToken)
               .ignoreContentType(true);
 String response = requestInfo.post().body().text();
 return toObject(response, TokensResponse.class);
}

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

public Connection loginConnection(String username, String password) {
  Connection login = connection(LOGIN_BASE_URL);
  return login
      .data("go_to", "news")
      .data("acct", username)
      .data("pw", password)
      .header("Origin", ConnectionProvider.BASE_URL)
      .followRedirects(true)
      .referrer(ConnectionProvider.BASE_URL + ConnectionProvider.LOGIN_URL_EXTENSION)
      .method(Connection.Method.POST);
}

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

/**
 * Method which retrieve the cookie saying that we are logged in
 */
public boolean login() throws IOException {
  final String loginUrl = this.mShaarliUrl;
  try {
    Connection.Response loginPage = this.createShaarliConnection(loginUrl, true)
        .data("login", this.mUsername)
        .data("password", this.mPassword)
        .data("token", this.mToken)
        .data("returnurl", this.mShaarliUrl)
        .execute();
    this.mCookies = loginPage.cookies();
    loginPage.parse().body().select("a[href=?do=logout]").first()
        .attr("href"); // If this fails, you're not connected
  } catch (NullPointerException e) {
    return false;
  }
  return true;
}

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

@Override
protected void processData(RequestModel model) {
  if(model.getData() != null) {
    connection.data(model.getData());
  }
}

代码示例来源:origin: pl.edu.icm.polindex/polindex-core

public Document postQuery(String url, Map<String,String> parameters, int timeoutMillis) throws IOException {
    Preconditions.checkArgument(StringUtils.isNotBlank(url));
    
    Date start = new Date();
    Connection con = Jsoup.connect(url)
               .timeout(timeoutMillis)
               .ignoreHttpErrors(false);
    
    if (parameters != null && !parameters.isEmpty()) {
      con.data(parameters);
    }
        
    logger.info(".. sending POST request to "+url+ " ...");
    Document doc = con.post();        
    
    Date stop = new Date();		
    
    logger.info(".. document from ["+url+"] received & parsed in "+ BeanStats.formatMillisPretty(stop.getTime() - start.getTime(), 0));
    
    return doc;
  }
}

代码示例来源: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

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: 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;
  }
}

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

public static Document postDocument(String url, Map<String, String> header, Map<String, String> data) 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")
      .headers(header)
      .data(data)
      .timeout(10000)
      .validateTLSCertificates(false)
      .post();
}

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

public static void main(String[] args) throws IOException {
  try {
    String url = "https://www.oschina.net/home/login";
    String userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36";
    Connection.Response response = Jsoup.connect(url).userAgent(userAgent).method(Connection.Method.GET)
        .execute();
    response = Jsoup.connect(url).cookies(response.cookies()).userAgent(userAgent)
        .referrer("https://www.oschina.net/home/login?goto_page=https%3A%2F%2Fmy.oschina.net%2Fbluetata")
        .data("username", "dietime1943@hotmail.com", "password", "lvmeng152300").data("save_login", "1")
        .followRedirects(false)
        .method(Connection.Method.POST).followRedirects(true).timeout(30 * 1000).execute();
    System.err.println(response.statusCode());
    
    Document doc = Jsoup.connect("https://my.oschina.net/bluetata").cookies(response.cookies())
        .userAgent(userAgent).timeout(30 * 1000).get();
    System.out.println(doc);
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: leftcoding/GankLy

@Override
  public void subscribe(ObservableEmitter<Document> subscriber) throws Exception {
    Document doc;
    try {
      doc = Jsoup.connect(url)
          .userAgent(USERAGENT)
          .timeout(TIME_OUT)
          .data(strings)
          .get();
      if (doc != null) {
        subscriber.onNext(doc);
      } else {
        subscriber.onError(new Throwable("service error"));
      }
    } catch (IOException e) {
      KLog.e(e);
      CrashUtils.crashReport(e);
      subscriber.onError(e);
    }
    subscriber.onComplete();
  }
});

相关文章