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

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

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

Connection.followRedirects介绍

[英]Configures the connection to (not) follow server redirects. By default this is true.
[中]配置与(不)跟随服务器重定向的连接。默认情况下,这是正确的。

代码示例

代码示例来源: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: bluetata/crawler-jsoup-maven

public static void main(String[] args) {
  // grab login form page first
  try {
    
    //lets make data map containing all the parameters and its values found in the form
    Map<String, String> mapParamsData = new HashMap<String, String>();
    mapParamsData.put("email", "dietime1943@bluetata.com");
    mapParamsData.put("password", "bluetata");
    
    Response loginResponse = Jsoup.connect("https://passport.jd.com/new/login.aspx")
        .userAgent(USER_AGENT)
        .timeout(TIMEOUT_UNIT * TIMEOUT_TIMES)
        .data(mapParamsData)
        .method(Method.POST)
        .followRedirects(true)
        .execute();
    
    System.out.println("Fetched login page");
    // System.out.println(loginResponse.toString());
    
   //get the cookies from the response, which we will post to the action URL
    Map<String, String> mapLoginPageCookies = loginResponse.cookies();
    
    System.out.println(mapLoginPageCookies);
    
  } catch (Exception e) {
    e.printStackTrace();
  }
}

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

pageResp = Jsoup.connect(url)
    .followRedirects(true)
    .execute()
    .parse();

代码示例来源:origin: denghuichao/proxy-pool

public String nextPage() {
  String html = "";
  String url = pageUrl();
  pageIndex++;
  logger.info("fetching page: " + url);
  try {
    Connection connection = Jsoup.connect(url);
    for (String[] head : HEADERS) {
      connection.header(head[0], head[1]);
    }
    connection.timeout(4000).followRedirects(true);
    html = connection.execute().parse().html();//执行
  } catch (IOException e) {
    logger.info("fetch page error: " + e.getMessage());
  }
  return html;
}

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

.data(mapParamsData)
.method(Method.POST)
.followRedirects(true)
.execute();

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

con2.header("User-Agent", userAgent);  
Response login = con2.ignoreContentType(true).followRedirects(true).method(Method.POST)  
            .data(datas).cookies(cookies).referrer("https://registrar-console.centralnic.com/dashboard/login")
            .header("host", "registrar-console.centralnic.com")

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

protected Connection getConnection(String URL) {		
  return Jsoup.connect(URL)				   
        .ignoreContentType(true)
        .userAgent(this.userAgent)  
        .referrer(this.referrer)   
        .timeout(this.timeout) 
        .followRedirects(this.followRedirects);		           
}

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

con2.header(USER_AGENT, USER_AGENT_VALUE);
Response login = con2.ignoreContentType(true).followRedirects(true).method(Method.POST).data(datas).cookies(rs.cookies()).execute();

代码示例来源: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: BeelGroup/Docear-Desktop

.data(formData)
.ignoreHttpErrors(true)							
.followRedirects(false)
.execute();

代码示例来源: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: net.minidev/ovh-java-sdk-core

validForm.followRedirects(false);

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

/**
 * Helper method which create a new connection to Shaarli
 * @param url the url of the shaarli
 * @param isPost true if we create a POST request, false for a GET request
 * @return pre-made jsoupConnection
 */
private Connection createShaarliConnection(String url, boolean isPost){
  Connection jsoupConnection = Jsoup.connect(url);
  Connection.Method connectionMethod = isPost ? Connection.Method.POST : Connection.Method.GET;
  if (!"".equals(this.mBasicAuth)) {
    jsoupConnection = jsoupConnection.header("Authorization", "Basic " + this.mBasicAuth);
  }
  if (this.mCookies != null){
    jsoupConnection = jsoupConnection.cookies(this.mCookies);
  }
  return jsoupConnection
      .validateTLSCertificates(this.mValidateCert)
      .timeout(this.mTimeout)
      .followRedirects(true)
      .method(connectionMethod);
}

代码示例来源: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: BeelGroup/Docear-Desktop

.referrer(e.getUrl())
                .cookies(imgCookie)
                .followRedirects(false)
                .execute();
if(captchaResponse.statusCode() == 302 && captchaResponse.hasHeader("Location")){
                .referrer(e.getUrl())
                .cookies(cookies)
                .followRedirects(false)
                .execute();
  Map<String, String> abuseCookies = abuseResponse.cookies();

代码示例来源:origin: persado/stevia

connect.followRedirects(true);
connect.userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:29.0) Gecko/20100101 Firefox/29.0");
connect.timeout(60000);

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

/**
 * Jsoup을 이용한 HTML 코드 파싱.
 *
 * @param eachArchiveAddress 실제 만화가 담긴 아카이브 주소
 * @return 성공하면 html 코드를 리턴
 */
private String getHtmlPageJsoup(String eachArchiveAddress) throws Exception {
  print.info("고속 연결 시도중...\n");
  // pageSource = Html코드를 포함한 페이지 소스코드가 담길 스트링, domain = http://wasabisyrup.com <-마지막 / 안붙음!
  String pageSource = null;
  // POST방식으로 아예 처음부터 비밀번호를 body에 담아 전달
  Response response = Jsoup.connect(eachArchiveAddress)
      .userAgent(UserAgent.getUserAgent())
      .header("charset", "utf-8")
      .header("Accept-Encoding", "gzip") //20171126 gzip 추가
      .timeout(MAX_WAIT_TIME) // timeout
      .data("pass", PASSWORD)    // 20180429 기준 마루마루에서 reCaptcha를 사용하기에 의미없음
      .followRedirects(true)
      .execute();
  Document preDoc = response.parse(); //받아온 HTML 코드를 저장
  // <div class="gallery-template">이 만화 담긴 곳.
  if (preDoc.select("div.gallery-template").isEmpty()) {
    throw new RuntimeException("Jsoup Parsing Failed: No tag found");
  } else { // 만약 Jsoup 파싱 시 내용 있으면 성공
    pageSource = preDoc.toString();
  }
  print.info("고속 연결 성공!\n");
  return pageSource; //성공 시 html코드 리턴
}

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

.followRedirects(params.isFollowRedirects())
.ignoreContentType(GLOBAL_CONFIG.isIgnoringContentType())

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

Jsoup.connect("").followRedirects(false).execute();

相关文章