Java网络爬虫crawler4j学习笔记<15> FormAuthInfo类

源代码

package edu.uci.ics.crawler4j.crawler.authentication;

import javax.swing.text.html.FormSubmitEvent.MethodType;
import java.net.MalformedURLException;

/**
 * Created by Avi Hayun on 11/25/2014.
 *
 * FormAuthInfo contains the authentication information needed for FORM authentication (extending AuthInfo which has all common auth info in it)
 * Basically, this is the most common authentication, where you will get to a site and you will need to enter a username and password into an HTML form
 */
public class FormAuthInfo extends AuthInfo {

  private String usernameFormStr;
  private String passwordFormStr;

  /**
   * Constructor
   *
   * @param username Username to login with
   * @param password Password to login with
   * @param loginUrl Full login URL, starting with "http"... ending with the full URL
   * @param usernameFormStr "Name" attribute of the username form field
   * @param passwordFormStr "Name" attribute of the password form field
   *
   * @throws MalformedURLException Make sure your URL is valid
   */
  public FormAuthInfo(String username, String password, String loginUrl, String usernameFormStr, String passwordFormStr) throws MalformedURLException {
    // 使用form表单,post方法进行登录验证
    super(AuthenticationType.FORM_AUTHENTICATION, MethodType.POST, loginUrl, username, password);

    this.usernameFormStr = usernameFormStr;
    this.passwordFormStr = passwordFormStr;
  }

  /**
   * @return username html "name" form attribute
   */
  public String getUsernameFormStr() {
    return usernameFormStr;
  }

  /**
   * @param usernameFormStr username html "name" form attribute
   */
  public void setUsernameFormStr(String usernameFormStr) {
    this.usernameFormStr = usernameFormStr;
  }

  /**
   * @return password html "name" form attribute
   */
  public String getPasswordFormStr() {
    return passwordFormStr;
  }

  /**
   * @param passwordFormStr password html "name" form attribute
   */
  public void setPasswordFormStr(String passwordFormStr) {
    this.passwordFormStr = passwordFormStr;
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值